MATLAB Answers

logarithmically spaced vector in a certain range

187 views (last 30 days)
How to create a logarithmically spaced vector say from values 3 to 10? Thank you!

  0 Comments

Sign in to comment.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 3 Oct 2014
Edited: Azzi Abdelmalek on 3 Oct 2014
pas=0.1
t=log(3):pas:log(10)
out=exp(t)
%or
n=10 % number of samples
out=exp(linspace(log(3),log(10),n))

  5 Comments

Show 2 older comments
Nuchto
Nuchto on 3 Oct 2014
In other words, how would you then create an exponentially spaced vector? Thanks in advance.
Azzi Abdelmalek
Azzi Abdelmalek on 3 Oct 2014
n=10 % number of samples
out=log(linspace(exp(3),exp(10),n))

Sign in to comment.

More Answers (2)

Nathan Porter
Nathan Porter on 7 Apr 2017
Like Marco, I would suggest using logspace. For example,
logspace(1,3,10)
creates a vector of 10 logarithmically spaced values between 10^1 and 10^3. If you instead want the bounds to be determined by a value and not the exponent, I generally use the following:
logspace(log10(3),log10(10),10)
This will create a vector of 10 logarithmically spaced values between 3 and 10.

  0 Comments

Sign in to comment.


Marco
Marco on 3 Oct 2014
To my knwoledge you could just use the built-in command logspace.

  0 Comments

Sign in to comment.


Translated by