How to find whether an array is logarithmically spaced

4 次查看(过去 30 天)
I have linearly, logarithmically and randomly spaced arrays. I need to tell them apart, but I am having trouble to determine whether an array is logarithmically spaced. Help is most appreciated!
  2 个评论
Bjorn Gustavsson
Bjorn Gustavsson 2021-11-26
What have you tried, have you looked at how the spacing varies with the magnitude of the elements?
Turaç Aydogan
Turaç Aydogan 2021-11-26
I am using this code to determine whether it is linearly spaced:
range(x(2:end)-x(1:end-1)) % if this is equal to zero I accept that the array is linearly spaced. (where x is a row vector)
However, I could not yet find a good way to determine whether the arrays are log-spaced, because I need to tell apart between log-spaced and randomly spaced arrays as well.

请先登录,再进行评论。

采纳的回答

Mathieu NOE
Mathieu NOE 2021-11-26
well
if you have a criteria that works for lin spaced arrays (like checking that std(diff(y)) is always below a very low threshold)
you can easily covert a log speced array to a lin spaced array by taking the log of it
demo :
y_log = logspace(1,3,100);
% nb : y = 10 .^ linspace(d1, d2, n);
y_lin = log10(y_log); % conversion from log to lin spacing
check = std(diff(y_lin))
check = 2.1980e-16
  7 个评论

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by