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

5 Ansichten (letzte 30 Tage)
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)

Akzeptierte Antwort

André
André am 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 Kommentare
Walter Roberson
Walter Roberson am 28 Okt. 2016
Lichen WANG comments to Lamia Kasmi:
Your solution 'drawnow' really helps me. Thanks a lot.
Fiona Macfarlane
Fiona Macfarlane am 27 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Errorbars finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by