MATLAB: Two colors in Bars

barhistogram

Hello,
I Need a litte help with bar scales… I have two bars, that should be named 'meanleft' and 'meanright`. I calculated the mean values of two Sensors. Now I Need 'meanleft' in green and 'meanright`in red. It seems to be easy, but I don't get ist, how it is done… Please help me 🙂
code:
c = categorical({'Meanleft','Meanright'});
values=[meanleft meanright];
bar(c,Werte);

Best Answer

y = [4.2; 4.6; 5]; %The data.
figure;
hold on
colors = hsv(numel(y));
for i = 1:numel(y)
bar(i, y(i),'facecolor', colors(i,:));
end