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),
  1 件のコメント
Angela
Angela 2018 年 9 月 14 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by