Generate a numerical series
Mostrar comentarios más antiguos
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 comentario
Respuesta aceptada
Más respuestas (1)
John D'Errico
el 28 de En. de 2022
Editada: John D'Errico
el 28 de En. de 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.
Categorías
Más información sobre Direction of Arrival Estimation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!