Generate a numerical series
Afficher commentaires plus anciens
Hi everyone, I want to generate this vector: 1e-8, 1e-9, 1e-10, 1e-11, 1e-12, 1e-13, 1e-14.
How can i do it?
Thanks
1 commentaire
Réponse acceptée
Plus de réponses (1)
John D'Errico
le 28 Jan 2022
Modifié(e) : John D'Errico
le 28 Jan 2022
While @DGM is correct (+1 from me on that answer, please accept that answer, as it is the correct one), in that it is what I would do immediately, there are always many ways to do things like this. The alternative I can think of immediately is to use cumprod with repmat:
format long g
v = cumprod([1e-8,repmat(0.1,1,6)])
fprintf('%g\n',v.') % for sake of clarity
I could also have used cumprod, in conjunction with repelem instead of repmat. That would be slightly less kludgy looking.
cumprod([1e-8,repelem(0.1,6)])'
Then I think of logspace, which does work nicely. In fact, logspace is a pretty clean looking solution. Still not as obvious in my eyes as that which DGM proposed.
logspace(-8,-14,7).'
And of course, there is this devious solution:
exp((-8:-1:-14)*log(10)).'
which is technically correct, exceot that floating point trash appears in the least significant bits. But 9.99999999999999e-9 is technically 1e-8, exept for an error in the least significant bit of the result.
I can stop here, but with some effort, I'd bet there are more.
Catégories
En savoir plus sur Direction of Arrival Estimation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!