Hello Community,
I am looking to colour some bar plots individually when a condition is met, ie if they have a value of 4, they will be coluored green, if valued 3 they are magenta and so on.
Following an answer I found by Andrew Schultz here I have put the following together:
% run for loop to colour data individually & when data conditions are met
for i = 1:length(pltvar1srt) h=bar(i,pltvar1srt(i)); if pltvar1srt(i) == x2634(1,11) && x2634(1,16) set(h,'FaceColor','b'); hlegend(1) = h; elseif pltvar1srt(:,2) == 4 set(h,'FaceColor','g'); hlegend(2) = h; elseif pltvar1srt(:,2) == 3 set(h,'FaceColor','m'); hlegend(3) = h; elseif pltvar1srt(:,2) == 2 set(h,'FaceColor','r'); hlegend(4) = h; else pltvar1srt(:,2) == 1 set(h,'FaceColor','k'); hlegend(5) = h; endend
but unfortunately what happens is I get a single bar coloured 'b' – so the first condition is met, but the rest of the bars end up coloured 'k', so the last condition is met and overwrites all the other colours.
Could anyone advise on how to fix my loop please?
Many thanks,
10B.
Best Answer