How can I change the width of horizontal lines of error bars in ERRORBAR plot in MATLAB 2015b?

4 views (last 30 days)
I am working with MATLAB 2015b and when using the ERRORBAR function, I would like to be able to change the length of the horizontal lines appearing on top and bottom of the error bars.
This question has been answered for the 2014 version of MATLAB but the solution doesn't work for the newer version of MATLAB.
Thanks in advance for your help.
Example:
x = [1 2 3 4];
y = [1 2 1 2];
dy = [0.1 0.1 0.1 0.1];
errorbar(x,y,dy)

Accepted Answer

André
André on 4 Feb 2016
The solution is hidden in the comments of Arnaud's errorbar_tick.m.
Edit the original errorbar_tick.m, find the if-else-structure below "% Plot error bars" and replace it with the code Matt posted in the comments:
if strcmpi(flagtype,'errorbar') % ERRORBAR(...)
x = h.Bar.VertexData(1,:); % Retrieve bar xdata from errorbar
dp = length(x)/3; % 3 data points per error bar
m = 1; % Multiplier for addition/subtraction
for ii = 1:dp
m = -1*m; % Switch between subtraction and addition
x(dp+ii:dp:end) = x(ii)+m*w/2; % Change xdata with respect to the chosen ratio
end
h.Bar.VertexData(1,1:end) = x;
else
error('Please enter an ErrorBar object!');
end
Works fine for me on 2015b!
  3 Comments
Fiona Macfarlane
Fiona Macfarlane on 27 Oct 2017
This works for me on 2015b, however when I save the figure (as a .fig file) the width reverts back to the previous situation. Does anyone know how to stop this. I am aware that taking screen-shots is a work around, however this is very time consuming and the quality is not great.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!