How to permute the rows and columns in a matrix ?

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

 採用された回答

Wayne King
Wayne King 2013 年 12 月 30 日
編集済み: Wayne King 2013 年 12 月 30 日

1 投票

Swapping the columns
idx = [4 2 3 1];
B = A(:,idx);
Swapping the rows
idx = [3 2 1 4];
C = A(idx,:);

その他の回答 (2 件)

Daniel Morais
Daniel Morais 2017 年 3 月 21 日

1 投票

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.
Sean de Wolski
Sean de Wolski 2013 年 12 月 30 日

0 投票

So
A([4,1],:) = A([1,4],:)
?

1 件のコメント

Nguyen Trong Nhan
Nguyen Trong Nhan 2013 年 12 月 30 日
cannot permute between columns ?

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMathematics and Optimization についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by