Sort

1 visualización (últimos 30 días)
Salvatore Turino
Salvatore Turino el 20 de Mzo. de 2012
Hello i want to know if exist a function that generate numbers in a range that i want to fix. for example i need to generate 22 numbers in this range: 0.5000 and 0.600
can you help me? thank you
  1 comentario
Aldin
Aldin el 20 de Mzo. de 2012
Here:
0.5:0.1/20:0.6

Iniciar sesión para comentar.

Respuestas (2)

Aldin
Aldin el 20 de Mzo. de 2012
Here:
0.5:0.1/20:0.6
Beacuase: (0.6 - 0.5)/20
  5 comentarios
Oleg Komarov
Oleg Komarov el 20 de Mzo. de 2012
In my case is 22.
Geoff
Geoff el 20 de Mzo. de 2012
Oleg is correct: length( 0.5:0.1/20:0.6 ) is 21. You really should use linspace if you want a linear sequence with a specified number of elements. That's what it's there for.

Iniciar sesión para comentar.


Geoff
Geoff el 20 de Mzo. de 2012
You haven't really specified if you want a sequence or just a set of numbers. Picking up on your term 'generate', perhaps you meant this:
randarr = @(lo, hi, n) lo + (hi-lo) * rand(1,n);
data = randarr(0.5, 0.6, 22);
That creates a bunch of random numbers in your specified range. Note I've wrapped it in an anonymous function to give the same syntax as linspace.
  1 comentario
Geoff
Geoff el 20 de Mzo. de 2012
Oops, just realised I specified that anonymous function incorrectly. Fixed.

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by