how to set log scale range

조회 수: 28 (최근 30일)
Megha
Megha 2018년 8월 6일
댓글: Megha 2018년 8월 6일
is it possible to set the range of matlab plot
set(gca,'XTick',(6:2:14),'XTickLabel',(6:2:14),'YTick',(1E-30:1E2:1E-22),...
'YTickLabel',(1E-30:1E2:1E-22));
However, it gives me wrong yticklabel, I want yticklabel like '1E-30', '1E-28', '1E-26', '1E-24', '1E-22'
what is the correct range (1E-30:1E2:1E-22) that i could use to define this?
  댓글 수: 2
Stephen23
Stephen23 2018년 8월 6일
편집: Stephen23 2018년 8월 6일
Both the colon and linspace operators use linear steps. If you want logarithmically spaced values, then use logspace, e.g.:
>> logspace(-30,-22,5)
ans =
1e-030 1e-028 1e-026 1e-024 1e-022
But for plotting you don't need to create these labels anyway: see Jan's answer.
Megha
Megha 2018년 8월 6일
Thank you stephen

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

채택된 답변

Jan
Jan 2018년 8월 6일
편집: Jan 2018년 8월 6일
yt = logspace(-30, -22, 5);
set(gca, 'XTick', 6:2:14, 'XTickLabel', 6:2:14, ...
'YTick', yt, 'YTickLabel', yt, ...
'XLim', [6, 14], 'YLim', [1e-30, 1e-22], ...
'YScale', 'log');
Use logspace to get the Y-ticks. Set the ranges accordingly and set Y-scaling to logarithmic.
By the way: You do not have to define the tick labels, if they are the same as the tick values.
  댓글 수: 3
Jan
Jan 2018년 8월 6일
Set 'YTickLabel' to:
sprintfc('10^%d', log(yt))
In modern Matlab versions try e.g. also:
compose('10^%d', -30:2:22)
Megha
Megha 2018년 8월 6일
yt = compose('10^%d', -2:1:3);
set(gca, 'XTick', (1:1:6), 'XTickLabel', 1:1:6, ...
'YTick', (1E-2:1E3), 'YTickLabel', yt);
please check this, it seems there is some error somewhere

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

추가 답변 (0개)

카테고리

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