How can I have n randomly generated vectors?

1 visualización (últimos 30 días)
Sherwin
Sherwin el 1 de Oct. de 2016
Comentada: Sherwin el 2 de Oct. de 2016
Hi, I want to generate n random vectors. The problem is I put it in the loop and the vector is being replaced in every run, but I need to have all of the n vectors.
for n= 1:50
A=rand(1,5);
end
How can I have n random vectors as an output?

Respuesta aceptada

Walter Roberson
Walter Roberson el 2 de Oct. de 2016
for n= 1:50
A(n,:)=rand(1,5);
end
or
for n= 1:50
A{i}=rand(1,5);
end
  2 comentarios
Sherwin
Sherwin el 2 de Oct. de 2016
Thank you.
Sherwin
Sherwin el 2 de Oct. de 2016
By the way is there any way that I get all of them in a row?

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 2 de Oct. de 2016
Store the vectors in rows of A
A = rand(50, 5);
Anytime you need one of the vectors, just reference a row of A
thisVector = A(row, :);
  5 comentarios
Image Analyst
Image Analyst el 2 de Oct. de 2016
Try one of these options:
m = magic(3)
% Get m going down columns
mRow = m(:)'
% Get m going across rows
temp = m';
mRow = temp(:)'
m =
8 1 6
3 5 7
4 9 2
mRow =
8 3 4 1 5 9 6 7 2
mRow =
8 1 6 3 5 7 4 9 2
Sherwin
Sherwin el 2 de Oct. de 2016
Thank you so much!

Iniciar sesión para comentar.

Categorías

Más información sobre Automotive 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