Create a random Matrix
1 回表示 (過去 30 日間)
古いコメントを表示
I have a 8 column vector n*1. Can I create a Random matrix of n*8?
The function must take one value from each vector and create a matrix with 8 columns and n rows.
Please help me :-)
2 件のコメント
Jan
2011 年 10 月 24 日
"I have a 8 column vector" sounds like a single vector. But "from each vector" might mean n vectors. Confusing.
採用された回答
Andrei Bobrov
2011 年 10 月 24 日
A1,A2,..,A8 - your vectors (nx1), let n = 5;
for j1 = 1:8, eval([sprintf('A%d',j1),'=randi(20,5,1)']); end
A = eval(['[',sprintf('A%d,',1:8),']'])
out=A(bsxfun(@plus,cell2mat(arrayfun(@(x)randperm(n)',(1:8),'un',0)),(0:7)*n))
3 件のコメント
Jan
2011 年 10 月 31 日
@Maurizio: Accepting an answer means, that it solves your problem sufficiently.
その他の回答 (1 件)
Walter Roberson
2011 年 10 月 24 日
rv(:,1) = randomvector1;
rv(:,2) = randomvector2;
rv(:,3) = randomvector3;
....
rv(:,4) = randomvector4;
rants = zeros(8, n);
for K = 1:n
rants(:,K) = A Random Selection of One Entry Per Column from rv
end
How to do "A Random Selection of One Entry Per Column from rv" is left to you to work on in more detail. I will hint that it involves using rand().
3 件のコメント
Walter Roberson
2011 年 10 月 30 日
floor(1 + n * rand())
will give you a random row number.
If I say much more than I will be completing your assignment for you.
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!