Using ind2sub in two different arrays

조회 수: 1 (최근 30일)
Angela
Angela 2018년 9월 13일
댓글: Angela 2018년 9월 14일
I have two arrays and i want to exclude the zeros from the first array(A) and then take the equivalent indices from array B.
A=[0 1 2; 2 1 4; 0 1 5];
B=[1 2 3; 2 4 2; 2 3 5];
[X,Y]=ind2sub(size(A),find(A>0))
Anew=A(X,Y)
Bnew=B(X,Y)
The result of the above is not what i want, Anew and Bnew are now larger than before. What am i doing wrong?

채택된 답변

Matt J
Matt J 2018년 9월 13일
편집: Matt J 2018년 9월 13일
This is not a situation that calls for ind2sub,
idx=(A~=0);
Anew=A(idx),
Bnew=B(idx),

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by