MATLAB: How to format YTickLabel with x10^n on when plotting a figure

decimal digitformatyticklabel

How to set the decimal digits of YTickLabel in figure? I tried some ways, but numbers with '%.4f' was too long, numbers with '%.2e' not good, either.
The following figure may be helpful for my question.
The left one uses
set (gca, 'YTickLabel', num2str (get (gca, 'YTick').' , '%.4f) )
The central one uses
set (gca, 'YTickLabel', num2str (get (gca, 'YTick').' , '%.2e) )
And the right one uses the default settings.
What I really want is as following figure.

Best Answer

y = rand(10,1)*5000;
ax = axes;
plot(y)
ax.YAxis.Exponent = 3;