MATLAB: How to use colormap for different bars.

bar chartbarscolor different barscolormap

I am trying to plot a bar chart with error bars, giving different colors to the individual bars using colormap function, but instead I get the same color for all bars. How can i set the bars following one specific colormap?
y = [4.2; 4.6; 5]; %The data.
s = [.3; .2; .6]; %The standard deviation.
h = bar(y);
colormap(hsv(h))
hold on
set(gca, ...
'XTickLabelMode', 'manual', ...
'XTickLabel', {'R0', 'R1', 'R2'})
h1 = errorbar(y,s,'r');
set(h1,'linestyle','none')

Best Answer

See if this helps.
y = [4.2; 4.6; 5]; %The data.
s = [.3; .2; .6]; %The standard deviation.
fHand = figure;
aHand = axes('parent', fHand);
hold(aHand, 'on')
colors = hsv(numel(y));
for i = 1:numel(y)
bar(i, y(i), 'parent', aHand, 'facecolor', colors(i,:));
end
set(gca, 'XTick', 1:numel(y), 'XTickLabel', {'R0', 'R1', 'R2'})
errorbar(y,s,'r');