I am new to programming so I am learning introductory to MATLAB I was wondering how you could change colours of bar in MATLAB.
this is my script. Can someone please help
To use two different colors depending on y
: compute a logical index depending on y
values and call bar
twice with appropriate arguments:
x = [1:8];
y = [20 30 40 50 60 70 80];
ind = y < 40; %// logical index
bar(x(ind), y(ind), 'facecolor', 'b', 'edgecolor', 'k') %// blue bars, black edge
hold on %// keep plot
bar(x(~ind), y(~ind), 'facecolor', 'g', 'edgecolor', 'k') %// green bars, black edge
set(gca,'xtick',x)