How can I have n randomly generated vectors?

조회 수: 1 (최근 30일)
Sherwin
Sherwin 2016년 10월 1일
댓글: Sherwin 2016년 10월 2일
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?

채택된 답변

Walter Roberson
Walter Roberson 2016년 10월 2일
for n= 1:50
A(n,:)=rand(1,5);
end
or
for n= 1:50
A{i}=rand(1,5);
end
  댓글 수: 2
Sherwin
Sherwin 2016년 10월 2일
Thank you.
Sherwin
Sherwin 2016년 10월 2일
By the way is there any way that I get all of them in a row?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2016년 10월 2일
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
Image Analyst
Image Analyst 2016년 10월 2일
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 2016년 10월 2일
Thank you so much!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by