Plot step function with y-axis in log-scale

조회 수: 9 (최근 30일)
Rayne
Rayne 2016년 4월 9일
댓글: Rayne 2016년 4월 9일
Hi,
How can I plot something like this?
I can only either use semilogy to plot the graph in log scale (without step function), or plot the step function (using "stairs" function) but with the y-axis in terms of the exponential (by taking the log of the y-values first).
How do I do both?
Thank you.
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 9일
The question is not clear
Rayne
Rayne 2016년 4월 9일
Basically, I'm trying to create the type of plot in the given picture, i.e. step function on a log-scale y-axis. I could only get either a smooth curve on a log scale, or a step function on a non-log-scale. How do I do both?

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

채택된 답변

Walter Roberson
Walter Roberson 2016년 4월 9일
If you are trying to get one line to be in log y scale and another to be in linear y scale, then you should plotyy() and set one of the axes to 'yscale' 'log'
If you are having problems that somehow stairs() does not look right with semilogy, then I do not seem to reproduce that in R2014a.
But if you happen to need some code to reproduce stairs() in terms of plot(), then:
plot( [x(1),kron(x(2:end),[1 1])], [kron(y(1:end-1),[1 1]),y(end)] )
  댓글 수: 1
Rayne
Rayne 2016년 4월 9일
Thanks, I managed to plot it using something like
stairs(1:10, 2*(1:10));
set(gca, 'YScale', 'log')

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by