How to find whether an array is logarithmically spaced

7 views (last 30 days)
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 Comments
Turaç Aydogan
Turaç Aydogan on 26 Nov 2021
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.

Sign in to comment.

Accepted Answer

Mathieu NOE
Mathieu NOE on 26 Nov 2021
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 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!