MATLAB Answers

random permutation for a matrix

39 ビュー (過去 30 日間)
shobhit mehrotra
shobhit mehrotra 2015 年 4 月 15 日
コメント済み: shobhit mehrotra 2015 年 4 月 16 日
I have a 2x5 matrix, A. I want to randoming sort both of the rows together, so that the second is still a function of the first row.
A = [ 2 5 9 11 23; 4 1 7 9 12]
One random permutation may look like
B= [5 11 9 2 23; 1 9 7 4 12]
The 1st and 2nd row are still the same ratio
Im trying to use the function randperm
Thanks

採用された回答

pfb
pfb 2015 年 4 月 15 日
That should be easy
i = randperm(5);
should give you the permutated indices, so that
B = A(:,i);
is the permutation of the columns of A according to those new indices.
  1 件のコメント
shobhit mehrotra
shobhit mehrotra 2015 年 4 月 16 日
Thanks!

サインインしてコメントする。

その他の回答 (0 件)

製品

Community Treasure Hunt

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

Start Hunting!

Translated by