MATLAB: How to add error bars to scatter plots

MATLAB

I have a scatter plot and want to add error bars. The "errorbar" function is not giving me correct results. How do I do this?

Best Answer

The function "scatter" does not currently support error bars. However, these can be achieved by overlaying the results of "errorbar" on top of "scatter", like so:
>> x = [1,2,3];
>> y = x.^2;
>> scatter(x,y);
>> axis([0,4,0,10]);
>> hold on;
>> err = ones(size(x));
>> errorbar(x, y, err, 'LineStyle','none');
An enhancement request has been submitted for this feature so it will be considered for future releases of MATLAB.