Yes, of course. Callbacks are evaluated in the base workspace. If you use a variable, which is defined in a function, it is not known when the callback runs.
Better use function for callbacks and store variables in the figure by guidata.
uimenu(ylim_menu, 'Label', 'auto', 'Callback', {@uimenu_Callback, 'auto'});
uimenu(ylim_menu, 'Label', 'manual', 'Callback', {@uimenu_Callback, '01'});
...
function uimenu_Callback(uimenuH, EventData, Command)
handles = guidata(uimenuH);
switch Command
case '01'
set(handles.Fig3_axes, 'YLim', [0, 1]);
case 'auto'
set(handles.Fig3_axes, 'YLimMode', 'auto');
otherwise
error('Unknown command - programming error');
end
Now the contents of the variable Fig3yLim can by added as 4th input argument.
Defining callbacks as strings is supported for backward compatibility with Matlab 5.3 (1999). Using function handles is more secure and efficient.
Best Answer