How do I store row swap information in a vector?
1 view (last 30 days)
Show older comments
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 Comments
Image Analyst
on 22 Oct 2012
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.
Answers (1)
Sachin Ganjare
on 22 Oct 2012
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 Comments
See Also
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!