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.
댓글 수: 0
채택된 답변
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
2019년 6월 21일
idx = setdiff(1:length(A),B); % indexes which are not in B
A(idx) = 0;
추가 답변 (1개)
madhan ravi
2019년 6월 21일
Probably you want:
idx = setdiff(1:numel(A),B);
A(idx) = 0;
댓글 수: 2
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 Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!