How to permute the rows and columns in a matrix ?
53 次查看(过去 30 天)
显示 更早的评论
for example: I have matrix A: A = [1 2 3 4;5 6 7 8;9 10 11 12;13 14 15 16] how to permute between column 1 and column 4 ? how to permute between row 1 and row 3 ? thanks
0 个评论
采纳的回答
Wayne King
2013-12-30
编辑:Wayne King
2013-12-30
Swapping the columns
idx = [4 2 3 1];
B = A(:,idx);
Swapping the rows
idx = [3 2 1 4];
C = A(idx,:);
0 个评论
更多回答(2 个)
Daniel Morais
2017-3-21
Utilize x = x( : , randperm(c)), onde x é a matriz e c o número de colunas de x. O mesmo vale para a permutação de linhas: x = x( randperm(l) , : ) onde l é o número de linhas.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 General Applications 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!