How to shuffle randomly first raw of a matrix so its corresponding value in the column shuffles with it

2 ビュー (過去 30 日間)
I have a matrix
X=[N1...N5 ; M1...M5];
I want to shuffle the N values so they have their corresponding M values in the second row.
For example:
If N values are shuffled as: N3, N1, N5, N4, N2
then, the new vector will be:
X=[N3, N1, N5, N4, N2 ; M3, M1, M5, M4, M2]
** This matrix is just an example, I will have to shuffle a much larger matrix a several times (each time shuffles randomly)
Help please

回答 (1 件)

Matt J
Matt J 2022 年 6 月 26 日
編集済み: Matt J 2022 年 6 月 26 日
X=rand(2,5)
X = 2×5
0.1792 0.3018 0.7249 0.2244 0.7763 0.9590 0.4391 0.9836 0.8612 0.9649
X=X(:,[3,1,5,4,2])
X = 2×5
0.7249 0.1792 0.7763 0.2244 0.3018 0.9836 0.9590 0.9649 0.8612 0.4391
  2 件のコメント
Paz Yedidim
Paz Yedidim 2022 年 6 月 26 日
I need to shuffle it randomly
I gave this shuffle order for the example only
Matt J
Matt J 2022 年 6 月 26 日
use randperm to generate a randomized shuffle of the inidces.

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

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by