MATLAB: How do i use a pushbutton from the GUI to perform some calculations calling from some popupmenus i have

guipushbutton

i am creating a GUI to calculate resistor values. i have 5 popupmenus to choose the colour of the bands and then i want a pushbutton to perform the calculations and then display the answer on the GUI. here is the code for one of my popupmenus for an example.
% --- Executes on selection change in popupmenu4.
function popupmenu4_Callback(hObject, eventdata, handles)
contents = cellstr(get(hObject,'String'));
popchoice = contents{get(hObject,'Value')};
if (strcmp(popchoice, 'Black'))
popVal = 0;
elseif (strcmp(popchoice, 'Brown'))
popVal = 1;
elseif (strcmp(popchoice, 'Red'))
popVal = 2;
elseif (strcmp(popchoice, 'Orange'))
popVal = 3;
elseif (strcmp(popchoice, 'Yellow'))
popVal = 4;
elseif (strcmp(popchoice, 'Green'))
popVal = 5;
elseif (strcmp(popchoice, 'Blue'))
popVal = 6;
elseif (strcmp(popchoice, 'Violet'))
popVal = 7;
elseif (strcmp(popchoice, 'Grey'))
popVal = 8;
elseif (strcmp(popchoice, 'White'))
popVal = 9;
end
assignin('base','popVal',popVal);
% this popupmenu is my band1 for the calculations
i have 5 of these popupmenus that are almost identical.
here are the equations i want the values from the popupmenus to go through the button and diplay the answer:
x = ((band1 * 100) + (band2 * 10) + band3) * 10^(bandmultiplier); % this is for 5 bands
and
x = ((band1 * 10) + band2) * 10^(bandmultiplier); % this is for 4 bands
if the user doesn't put anything in for band 3 i want the button to go through the calculations for 4 bands.
the band tolerance isnt in the equations because i want it to be displayed separately.

Best Answer

Don't use assignin() at all! Simply get each band in the pushbutton callback. Don't use the popup callbacks at all. Just have this in the pushbutton callback:

band1 = handles.popup1.Value;
band2 = handles.popup2.Value;
band3 = handles.popup3.Value;
bandmultiplier= handles.popup4.Value;
x = ((band1 * 100) + (band2 * 10) + band3) * 10^(bandmultiplier);

and so on.