Matrix row swapping with respect to column
이전 댓글 표시
How to swap between two rows of matrix with respect to column? For example: matrix A is: 1 3 4; 2 4 5 and Y want to be 1 4 5;2 3 4 , only 2nd and 3rd coulm row values have to be interchanged.? I want a generalised equation so that when I input the column no,numbers between the said column to end in a particular row has to be swapped with the next row.
답변 (2개)
KALYAN ACHARJYA
2019년 7월 27일
편집: KALYAN ACHARJYA
2019년 7월 27일
"only 2nd and 3rd coulm row valuese have to be interchanged.?"
Y=[1 3 4; 2 4 5]
Z=Y;
Y(:,2)=Y(:,3);
Y(:,3)=Z(:,2);
Y
Result:
Y =
1 3 4
2 4 5
Y =
1 4 3
2 5 4
madhan ravi
2019년 7월 27일
I have no idea why Kalyan is making an easy task really harder but here is what you want:
Y = A;
Y(:,[2,3]) = flip(Y(:,[2,3]))
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!