Data point missing in if statement
Show older comments
The following piece of code only plots 4 points and it should plot 5 (not 6 because two points overlap). I was wondering if you could tell me how to fix it.
A = [5;5;5;3;3;2];
B = [10;4;10;10;4;4];
for n = 1:length(A)
if A(n) == 5
plot(A(n),B(n),'rx')
elseif A(n) == 3
hold on
plot(A(n),B(n),'bx')
else
hold on
plot(A(n),B(n),'gx')
end
end
axis([0 10 0 20])
Please note that I want to use if staments.
The output should be:

But the bottom red point is missing when using the code above...
1 Comment
John D'Errico
on 6 Apr 2019
Edited: John D'Errico
on 6 Apr 2019
And why exactly did you feel it necessary to post the same identical question two days in a row? Your first question got an answer. If you post it again, I will start closing the new ones. Just get someone to clarify things, rather than posting over and over again.
Accepted Answer
More Answers (0)
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!