MATLAB: How to color individual points on errorbar plot

colorfor loopMATLABplot

Hi,
I want to color the individual points of this errorbar plot. I tried doing it in the following way but it doesn't work.
means=[1 1 2 3 4];
standarddeviation=[0.1 0.2 0.2 0.3 0.35];
color=['b' 'm' 'b' 'm' 'b'];
errorbar(means, standarddeviation,'.','MarkerEdgeColor', color,'MarkerSize',20),;
I also tried plotting it in a for loop but that doesn't work at all.
means=[1 1 2 3 4];
standarddeviation=[0.1 0.2 0.2 0.3 0.35];
color=['m','m','k','g','r'];
for i = 1:numel(means)
errorbar(means(i), standarddeviation(i),'.'),'MarkerEdgeColor', color(i),;
hold on
end
Can someone help me fix this?

Best Answer

  • You need to plot with respect to an independent variable.
    Try this:
    means=[1 1 2 3 4];
    standarddeviation=[0.1 0.2 0.2 0.3 0.35];
    color=['m','m','k','g','r'];
    figure
    hold on
    for i = 1:numel(means)
    errorbar(i, means(i), standarddeviation(i),'.','MarkerEdgeColor', color(i))
    end
    hold off
    xlim([0 6])
    I chose the loop index ā€˜iā€™ for the independent variable here.
    .