Shuffle n rows of a matrix

2 vues (au cours des 30 derniers jours)
REMYA K
REMYA K le 15 Nov 2020
Commenté : REMYA K le 16 Nov 2020
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.

Réponse acceptée

Ameer Hamza
Ameer Hamza le 15 Nov 2020
Try this
M = rand(5);
idx = [randperm(3) 4 5];
M_shuffled = M(idx, :)
  5 commentaires
Ameer Hamza
Ameer Hamza le 15 Nov 2020
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 le 16 Nov 2020
It works...Thanks

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Discrete Math dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by