How to create random vectors of the same lengths?

21 visualizaciones (últimos 30 días)
Mark
Mark el 12 de Jun. de 2012
I am trying to get a random vector (2D) of the same length, say 'x'.
I thought about creating a list of numbers -1 to 1 for x values and then another one for from 1 to -1 for y values, and then randomly picking two numbers from the list, but this would give me vectors of all lengths and I don't know how to normalize them. I had all sorts of other ideas but none of them seem to be of much use.
Absolutely any help is greatly appreciated!
  1 comentario
Mark
Mark el 12 de Jun. de 2012
This is where I am now at, for 200 numbers between -1 and +1
>> N=200;
>> min=-1;
>> max=+1;
>> range=max-min;
>> a=range*rand(N,2).*sign(rand(N,2))-range/2;

Iniciar sesión para comentar.

Respuesta aceptada

Kevin Holst
Kevin Holst el 12 de Jun. de 2012
from the documentation: Examples
Generate values from the uniform distribution on the interval [a, b].
r = a + (b-a).*rand(100,1);
in your case you'd want:
a = min + (max-min).*rand(N,2);

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by