How to compare two arrays?
Afficher commentaires plus anciens
Example:
aa = [1 1 1 1 -1 -1 1 1 1 1 1 1 -1 -1 1]
and
bb = [NaN NaN NaN NaN 0.2 0.3 NaN 0.2 0.3 NaN NaN NaN 0.2 0.3 NaN]
and I want to generate third array such that it contains values in bb for every value that correspond to -1 in aa, and for every other value I should get NaN, and the size of resulted should remain same as aa and bb. So the result should look something like this:
cc = [NaN NaN NaN NaN 0.2 0.3 NaN NaN NaN NaN NaN NaN 0.2 0.3 NaN].
I am doing something like this:
cc = bb(aa == -1 | isnan(bb));
But the length or the size of the array changes.
Please advice.
Réponse acceptée
Plus de réponses (1)
Azzi Abdelmalek
le 28 Fév 2013
Modifié(e) : Azzi Abdelmalek
le 28 Fév 2013
cc=nan(1,numel(aa))
idx=find(aa==-1)
cc(idx)=bb(idx)
1 commentaire
Micky
le 28 Fév 2013
Catégories
En savoir plus sur Image Arithmetic dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!