MATLAB: Creating callback for each string of a popupmenu in GUI

callbackpopupmenustring

%I have a popupmenu in GUI and I created 3 strings (x,y,z) in this popupmenu. I need to create callback for each 3 strings. Each string has different codes so when user click one of them, related popupmenu's codes need to work.

Best Answer

Try this:
function popupmenu1_Callback(hObject, eventdata, handles)
try
% Get value of popup
selectedIndex = get(handles.popupmenu1, 'value');
% Take action based upon selection
if selectedIndex == 1
results = Function1();
elseif selectedIndex == 2;
results = Function2();
elseif selectedIndex == 3;
results = Function3();
end
catch ME
errorMessage = sprintf('Error in function %s() at line %d.\n\nError Message:\n%s', ...
ME.stack(1).name, ME.stack(1).line, ME.message);
fprintf(1, '%s\n', errorMessage);
uiwait(warndlg(errorMessage));
end
Related Question