logarithmically spaced vector in a certain range

130 vues (au cours des 30 derniers jours)
Nuchto
Nuchto le 3 Oct 2014
Commenté : Johann Martinez le 15 Mar 2021
How to create a logarithmically spaced vector say from values 3 to 10? Thank you!

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 3 Oct 2014
Modifié(e) : Azzi Abdelmalek le 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 commentaires
Azzi Abdelmalek
Azzi Abdelmalek le 3 Oct 2014
n=10 % number of samples
out=log(linspace(exp(3),exp(10),n))
Nuchto
Nuchto le 3 Oct 2014
Thank you!

Connectez-vous pour commenter.

Plus de réponses (2)

Nathan Porter
Nathan Porter le 7 Avr 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.
  1 commentaire
Johann Martinez
Johann Martinez le 15 Mar 2021
Thank Nathan, but what if I have a, b values equals to 0, 0.97, for example?
I mean, the logspaced vector is full of NaN, because of the negative logarithm...
thanks in advance

Connectez-vous pour commenter.


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

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by