Access matrix location on one matrix with the data location on another matrix

I have two matrix say A & B if I have data stored in A and the data location of desired values in B how could I access Values of matrix A who are located at locations B.

 채택된 답변

In case if A and B are vectors ,( 1 x n ) matrices
A(B) % It will give the values of A at indexes B

댓글 수: 3

I want to keep values of A on location B as it is and set all other to zero.
Thanks for the help....
idx = setdiff(1:length(A),B); % indexes which are not in B
A(idx) = 0;
Thank you so much this works !!!

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

추가 답변 (1개)

Probably you want:
idx = setdiff(1:numel(A),B);
A(idx) = 0;

댓글 수: 2

yes Exactly what I wanted
Beware this method works even if A is a matrix more than 1 dimension unlike the other.

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2019년 6월 21일

편집:

2019년 6월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by