How do I store row swap information in a vector?
조회 수: 1 (최근 30일)
이전 댓글 표시
Suppose I have 2 matrices A and B.. A is an NxN matrix and B is an Nx1 matrix. Now, I want to swap certain rows in A and store the information in an array P and use the array P to swap the rows in B. Is there a way to do this?
댓글 수: 2
Image Analyst
2012년 10월 22일
I don't know what P is - is it A with "certain rows" swapped? What does "use the array P to swap the rows in B" mean. How, given only that P matrix, are you supposed to know what to do with B? If you know which rows in A were swapped and you wanted to swap the same elements in B, you wouldn't even need P at all. Please give a small example (say N = 4 or 5) showing A, P, and B.
답변 (1개)
Sachin Ganjare
2012년 10월 22일
Command for swapping array:
For 3x3 Matrix A:
A([1 3], :) = A([3 1], :)
This will swap row 1 with 3.
Now you can use for loop for swapping the rows, at the same time saving swapped rows information in matrix P.
Then you run another loop for swapping rows in matrix B, but this time with swapping information present in matrix P.
Hope this helps!!!
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!