Generate new array with logarithmic spacing

조회 수: 19 (최근 30일)
IngDig
IngDig 2015년 4월 7일
댓글: IngDig 2015년 4월 7일
I have some experimental data (ydata and xdata), where xdata is an array with linear spacing. I would like to know how I can get my ydata in such a way that the elements are spaced as if xdata was on a logarithmic space.
In other words, I would like to have a new ydata vector (new_ydata) such that when I plot:
plot(new_ydata)
it would generate the same graph as when I plot:
semilogx(ydata)
Thanks

채택된 답변

Michael Haderlein
Michael Haderlein 2015년 4월 7일
I'm not sure what you want. You can get a logspaced array like this: Assume that x is your xdata and you want the log array to have 20 values:
xlog=logspace(log10(min(x)), log10(max(x)), 20)
ylog=interp1(x,y,xlog);
However, plot(xlog,ylog) will still look like plot(x,y), just the position of the markers differs. If you want to have the same optical output, you need to plot(log(x),y), but of course that will change the values on the axes (to the log values, obviously).
  댓글 수: 1
IngDig
IngDig 2015년 4월 7일
This will work fine for my purpose!
Thank you!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by