How to set the color in a for loop for a plot within the for loop with an if statement?
10 views (last 30 days)
Wolfgang McCormack on 12 Mar 2021
I have the following code but I don't like it. What I want is that we plot the entire t,e but set MarkerFaceColor of each point in the 50 x 50 plot based on the if statements. How should I get that done? when I add the set argument, it does not work at all and only plots a point at 50,50.
for t = 1:50
for e = 1:50
if ismember(t,1:0.01:4.99) & ismember(e,1:0.01:4.99)
elseif ismember(t,5:0.01:50) & ismember(e,5:0.01:50)
Veronica Taurino on 12 Mar 2021
Edited: Veronica Taurino on 12 Mar 2021
I don't get very well what you are asking for. You need to color t between 1 and 5 AND e between 1 and 5 in black, otherwise t between 5 (included) and 50 AND e between 5 (included) and 50 in red. With you code, I get this:
What is it wrong according to your needs?
Do you need something like this?
% random entries
plot(t,e,'og') % plot all together, just to check if you miss something
for ii = 1:50
if (t(ii)>=1 && t(ii)< 5) && (e(ii)>=1 && e(ii)< 5)
plot(t(ii),e(ii),'.k','MarkerFaceColor','k') %here I used . instead of o, just to check if points fall within the green ones
elseif (t(ii)>=5 && t(ii)<= 50) && (e(ii)>=5 && e(ii)<= 50)
this is the output (just one point respects the first condition and it is black).