Azzera filtri
Azzera filtri

Using ind2sub in two different arrays

1 visualizzazione (ultimi 30 giorni)
Angela
Angela il 13 Set 2018
Commentato: Angela il 14 Set 2018
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?

Risposta accettata

Matt J
Matt J il 13 Set 2018
Modificato: Matt J il 13 Set 2018
This is not a situation that calls for ind2sub,
idx=(A~=0);
Anew=A(idx),
Bnew=B(idx),

Più risposte (0)

Categorie

Scopri di più su Operators and Elementary Operations in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by