Shuffle n rows of a matrix

2 ビュー (過去 30 日間)
REMYA K
REMYA K 2020 年 11 月 15 日
コメント済み: REMYA K 2020 年 11 月 16 日
I have a 5*5 matrix, I want to shuffle first 3 rows of this but last two rows should remains same..any body please help.

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 11 月 15 日
Try this
M = rand(5);
idx = [randperm(3) 4 5];
M_shuffled = M(idx, :)
  5 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 11 月 15 日
Yes, you can do it like this
M = rand(10);
n = 3;
m = 7;
idx = [1:n-1 randperm(m-n+1)+(n-1) m+1:size(M,1)];
M_shuffled = M(idx, :)
REMYA K
REMYA K 2020 年 11 月 16 日
It works...Thanks

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDiscrete Math についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by