필터 지우기
필터 지우기

How to permute the rows and columns in a matrix ?

조회 수: 58 (최근 30일)
Nguyen Trong Nhan
Nguyen Trong Nhan 2013년 12월 30일
답변: Daniel Morais 2017년 3월 21일
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일
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일
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일
So
A([4,1],:) = A([1,4],:)
?

카테고리

Help CenterFile Exchange에서 Hypothesis Tests에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by