Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Neuro
Neuro le 23 Mar 2022
Commenté : Neuro le 23 Mar 2022
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 commentaires
Neuro
Neuro le 23 Mar 2022
Yes, but I didn't get the correct response so I decided to add more details here.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 23 Mar 2022
Modifié(e) : Jan le 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

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by