Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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!

Risposta accettata

Jan
Jan il 23 Mar 2022
Modificato: Jan il 23 Mar 2022
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

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by