Using a matrix values to point to another matrix rows&cols
Show older comments
Hi,
So matrix 1 is a 102x2 matrix full of x and y coordinates. Matrix 2 is a 102x3 matrix, where the second column values refer to which row in matrix one has relevant information. For all the values in matrix two column 2, I need the information in that row in matrix 1 put into a third matrix.
simply:
M1 = x y M2 = row.no M3 = xy of row
1 2 3 2 1
1 3 1 1 2
2 1 2 1 3
I've been trying variants of
%into every row in column 1 = for every col 2 in M2, the row in M1;
M3(:,1) = M1(M2(:,2),:);
But every change I make seems to not work, so I think I'm doing it totally wrong? I could possibly do it with a for loop but I'm still not sure how to use a value in a matrix to indicate the row in another matrix. Any advice would be much appreciated!
Accepted Answer
More Answers (0)
Categories
Find more on Resizing and Reshaping Matrices 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!