MATLAB: How to ensure that zoom is on by default when I open a figure

defaultfigureMATLABmodeonpanuimodezoom

I would like to have the figure's zoom mode on by default. That is, when I open the figure, I want the figure to already be in zoom mode. How can I do this?

Best Answer

In order to do this, consider using the 'CreateFcn' callback for a figure. This callback is designed to execute when a figure is created or opened. Using the 'CreateFcn' figure callback to set the zoom option to be on will allow the figure to be zoomable when it opens.
For example, refer to the following lines of code:
>> f=figure; % Create a figure
>> plot(1:10); % Create a plot on the figure
>> zoom on % Set the zoom option to be 'on'
>> f.CreateFcn='zoom on'; % Modify the 'CreateFcn' figure callback so that the zoom is turned on when the figure is created
>> savefig('Test1') % Save the figure to a file called 'Test1.fig'
After executing the code and opening the 'Test1.fig' file in MATLAB, the zoom option should be set to 'on'. For details of each line of code above, refer to the comment at the end of each line. For more information about figure callbacks and properties, please refer to the following link:
https://www.mathworks.com/help/matlab/ref/matlab.ui.figure-properties.html