How do I store row swap information in a vector?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Image Analyst
il 22 Ott 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.
Risposte (1)
Sachin Ganjare
il 22 Ott 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 Commenti
Vedere anche
Categorie
Scopri di più su Linear Algebra in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!