필터 지우기
필터 지우기

Column and row rearrangement

조회 수: 2 (최근 30일)
nur yusof
nur yusof 2016년 2월 23일
댓글: Star Strider 2016년 2월 25일
How to rearrange column and row matrix?For example, I have 10x10 matrix size. I want to move the 10th column and row into 1st column and row.Then,1st column and row will move to 2nd column and row. 2nd row and column will move to 3rd column and row. And also, repeat for next column and row.

채택된 답변

Star Strider
Star Strider 2016년 2월 23일
Use the circshift function. With it, you can do everything you seem to describe wanting to do with your matrix.
  댓글 수: 4
nur yusof
nur yusof 2016년 2월 25일
Ok.Noted. I have tried the code.It success to move the column and row that I want but, the matrix size is reduced.The original matrix size is 10x10, but at final it only had 6x6. Let me rephrase, what I really want to do:-
K[1:10,1:10] %original position of column & row matrix size
K2[2 4 6 8 10 1 3 5 7 9,2 4 6 8 10 1 3 5 7 9] %New arrangement of column and row position in matrix
Hope you can help me.
Star Strider
Star Strider 2016년 2월 25일
When I ran my code (and I just ran it again to be sure), the final ‘M’ matrix size was (10x10) and the (8x8) submatrix rows and columns were correctly rotated and correctly inserted back into the original (10x10) ‘M’ matrix when I examined it. I don’t understand how you got a (6x6) matrix with my code.
I’m not certain what you want as your result, but this looks correct to me:
K = randi(99,10)
K2 = K([2 4 6 8 10 1 3 5 7 9]',[2 4 6 8 10 1 3 5 7 9]')
You have to transpose the row and column reference vectors.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by