MATLAB: Force a scientific notation format

plotting

hi,
when i use this code, instead of forcing it to give me the x-axis as: 0,1,2,…,10 then x10^3 (3 is a superscript) it gives me the numbers as 1000,2000,…and so on…any idea?
x = 0:0.1e4:0.1e5;
y = randn(11,1);
plot(x,y,'b-o')
set(gca,'xtick',0:0.1e4:0.1e5);

Best Answer

x = 0:0.1e4:0.1e5;
y = randn(11,1);
plot(x,y,'b-o')
xVals = 0:0.1e4:0.1e5;
set(gca,'xtick',xVals);
set(gca,'XTickLabel',sprintf('%2.0e|',xVals));
The last line in the previous snippet sets the format for your XTickLabels. For more information on other formats:
doc sprintf
EDIT Exponent should appear at the right of the X-axis
x = 0:0.1e4:0.1e5;
y = randn(11,1);
plot(x,y,'b-o')
xVals = 0:0.1e4:0.1e5;
set(gca,'xtick',xVals);
expVal = 3; %exponent you want
set(gca,'XTickLabel',sprintf('%2.0f|',xVals./(10^expVal)));
pos = get(gca,'Position');
offset = 0.00; %how far to the right you want the exponent
annotation('textbox',[pos(1)+ pos(3)+offset, pos(2), 0.2, 0.2],...
'String',['$\times 10^' num2str(expVal) '$'],...
'Interpreter','latex',...
'VerticalAlignment','bottom',...
'EdgeColor','none')