Using a matrix values to point to another matrix rows&cols

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!

 채택된 답변

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

릴리스

R2019a

질문:

Mia
2020년 5월 8일

댓글:

Mia
2020년 5월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by