How to get the values from some of the coordinates?

조회 수: 2 (최근 30일)
Isti
Isti 2012년 4월 30일
I have matrix A like this:
A =
2 1 4 5 2
3 4 5 1 2
5 3 5 4 3
3 2 1 9 3
7 1 8 2 4
Then I have a matrix that decribe list of the coordinates is like this:
B =
1 2
3 4
4 1
So, the coordinate we can take from matrix B above is (1,2), (3,4), (4,1).
Then I want to produce the vector Y that consist of the value of matrix A which located is took from matrix B.
So the vector Y that will be produced is like this:
Y =
1
4
3
What to do?
Thanks before :')

채택된 답변

Jan
Jan 2012년 4월 30일
Y = A(sub2ind(size(A), B(:,1), B(:,2)));
  댓글 수: 2
Isti
Isti 2012년 4월 30일
thank you :)
Andrei Bobrov
Andrei Bobrov 2012년 4월 30일
A(bsxfun(@minus,B,[0 1])*[1;size(A,1)])

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 NaNs에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by