How to apply two masks simultaniously for plot

Hi all,
I have a data set of which I want to show the outcome in one plot. Four types of outcomes are possible: mask 1 & mask 2 are false, only one of those is true, and both are true. I can't figure out how the latter can be colored green. The last line of text is incorrect, but I can't find the right syntax.
Thank you all.
Koen
figure; hold on; % new figure window. enable overlaying of plots
plot(x,y,'r.'); % plot a red dot for all points
plot(x(mask1),y(mask1),'m.') % overwrite all points where mask1==true
plot(x(mask2),y(mask2),'c.') % overwrite all points where mask2==true
plot(x([mask2]&&[mask1]), y([mask2]&&[mask1]), 'g.')%overwrite all point where mask1 & mask2 are true.

 Réponse acceptée

dpb
dpb le 8 Déc 2021
ixBoth=mask2&mask1;
plot(x(ixBoth), y(ixBoth, 'g.')
Not the place for && short-circuit operator, but the single & for logical addressing/indexing.
I dunno if ML JIT optimizer is smart enough to recognize and eliminate the double-calculation of writing both indexing expressions explicitly or not so I built the temporary here.

1 commentaire

Koen vdL
Koen vdL le 8 Déc 2021
Thanks a lot, this works. I don't know why I didn't try this myself as it seems logical but I appreciate your answer!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by