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.

 채택된 답변

dpb
dpb 2021년 12월 8일

0 개 추천

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

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!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

제품

릴리스

R2018b

태그

질문:

2021년 12월 8일

댓글:

2021년 12월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by