MATLAB: How to prevent scientific notation on the axes in MATLAB R2015a and earlier releases

actionpostcallbackMATLABytickzoom

Is there a way to control the output of plots so that they don't automatically display in scientific notation?
I need something that enables me to control how the tick labels are displayed on the axes. That way, when I zoom in or out, I can force the label format to non-scientific.

Best Answer

If you are using MATLAB R2015b or a later release, please refer to the following MATLAB Answers post: 
In MATLAB R2015a and earlier releases, you can use the following method.
1. Plot your data.
>> x = rand(100, 1);
>> y = 1e-3*x;
>> plot(x, y)
2. Get a handle to the current figure and axes:
>> hFig = gcf
>> hAxes = gca
3. Define a function that reformats the tick labels as follows:
function reformatTickLabels(hAxes)
XTickLabel = get(hAxes,'XTick');
set(hAxes,'XTickLabel',num2str(XTickLabel'))
YTickLabel = get(hAxes,'YTick');
set(hAxes,'YTickLabel',num2str(YTickLabel'))
end
where "hAxes" is the axes handle.
4.  Call this function to format your tick labels, before zooming.
>> reformatTickLabels(hAxes);
5. Get the handle to the zoom mode object of the figure:
>> z = zoom(hFig);
7. Set the "ActionPostCallback" function on the zoom handle to the function "reformatTickLabels". This means that after you perform a zooming action, this callback function will be called and executed. In this way, the tick labels will stay in non-scientific format even after zoom events.
set(z,'ActionPostCallback',@zoomReformatLabels)
where "zoomReformatLabels" is defined as
function zoomReformatLabels(obj,evd)
reformatTickLabels(evd.Axes)
end
where "obj" is the handle to the figure that has been clicked on and "evd" is the object containing the structure of event data.
More information on the zoom callback functions can be found here:
https://www.mathworks.com/help/releases/R2020a/matlab/ref/zoom.html
Note: This link is from MATLAB R2020a documentation. Some things might not be applicable for MATLAB R2015a as expected.