Scientific notation values to the y axis label based on original data

조회 수: 5 (최근 30일)
Reid
Reid 2014년 5월 23일
댓글: Star Strider 2014년 5월 24일
Hey! I would like to automatically have the y-axis label updated based on the input values for the variable y. In this case I would like the line "-5" in the y-axis label replaced by "10^-5" (with the -5 shown as an exponent).
Thanks in advance for any help!
if true
% code
x=[1:3];
y=[.00002 .00004 .00006];
figure;
plot(x,y);
ylabexp=floor(log10(y(1)));
ylab = {'\uparrow';'\epsilon /';ylabexp;'M^{-1}'};
yh = ylabel(ylab);
set(yh,'rot',0)
ylabh2 = get(gca,'YLabel');
set(ylabh2,'Position',get(ylabh2,'Position') - [.1 0 0])
end
  댓글 수: 4
Star Strider
Star Strider 2014년 5월 24일
편집: Star Strider 2014년 5월 24일
I tried to run your code but couldn’t.
  1. PLEASE format your code — use the ‘[{}Code]’ button
  2. what is ‘yval’?
  3. Y not use semilogy?
Reid
Reid 2014년 5월 24일
Thanks for the help with the code button. I'm still getting "-5" in the y axis label and not "10^-5"
Attached is what i'm seeing when i run the code.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2014년 5월 24일
Change your ylabexp line to:
ylabexp=sprintf('10^{%d}',floor(log10(y(1))));
If I understand your question correctly, that should do what you want.

추가 답변 (1개)

Reid
Reid 2014년 5월 24일
Thanks!

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by