Shuffle n rows of a matrix
4 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Ameer Hamza
2020-11-15
Try this
M = rand(5);
idx = [randperm(3) 4 5];
M_shuffled = M(idx, :)
5 个评论
Ameer Hamza
2020-11-15
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, :)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NaNs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!