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

조회 수: 1 (최근 30일)
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.

채택된 답변

Chinmay Anand
Chinmay Anand 2019년 6월 21일
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
Chinmay Anand
Chinmay Anand 2019년 6월 21일
idx = setdiff(1:length(A),B); % indexes which are not in B
A(idx) = 0;

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

추가 답변 (1개)

madhan ravi
madhan ravi 2019년 6월 21일
Probably you want:
idx = setdiff(1:numel(A),B);
A(idx) = 0;
  댓글 수: 2
madhan ravi
madhan ravi 2019년 6월 21일
편집: madhan ravi 2019년 6월 21일
Beware this method works even if A is a matrix more than 1 dimension unlike the other.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by