MATLAB: Shuffle n rows of a matrix

shuffle

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.

Best Answer

Try this
M = rand(5);
idx = [randperm(3) 4 5];
M_shuffled = M(idx, :)