フィルターのクリア

How to shuffle rows in pairs in a 600 x 2 matrix that only contains integers?

2 ビュー (過去 30 日間)
Neuro
Neuro 2022 年 3 月 23 日
コメント済み: Neuro 2022 年 3 月 23 日
Hello. I have a 600 x 2 matrix called 'File', which only contains the following integers, in sequence:
10 1
30 2
50 1
70 8
90 3
10 5
40 6
50 2
(and the list repeats itself up to row 600).
I want to shuffle (randomize) the order of the rows in pairs, so row 2 is always preceded by row 1, row 4 is always preceded by row 3, and so on. Like each pair of rows was grouped.
a 600 x 1 matrix. They can have only 8 values, let's say 1, 2, 3, 4, 5, 6, 7, and 8. I want to randomize the order of the rows but in pairs so 1 is always followed by 2, and 3 is always followed by 4, 5 is always followed by 6, and 7 is always followed by 8. Like there were only 4 elements: 1-2, 3-4, 5-6, and 7-8. But in pairs in rows (within the same column).
Thank you!
  2 件のコメント
Arif Hoq
Arif Hoq 2022 年 3 月 23 日
編集済み: Arif Hoq 2022 年 3 月 23 日
Neuro
Neuro 2022 年 3 月 23 日
Yes, but I didn't get the correct response so I decided to add more details here.

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

採用された回答

Jan
Jan 2022 年 3 月 23 日
編集済み: Jan 2022 年 3 月 23 日
A = [10 1; ...
30 2; ...
50 1; ...
70 8; ...
90 3; ...
10 5; ...
40 6; ...
50 2];
s = size(A);
B = reshape(A, 2, s(1)/2, s(2));
B = B(:, randperm(s(1)/2), :);
B = reshape(B, s)
B = 8×2
50 1 70 8 90 3 10 5 10 1 30 2 40 6 50 2

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by