Effacer les filtres
Effacer les filtres

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

5 vues (au cours des 30 derniers jours)
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)

Réponse acceptée

André
André le 4 Fév 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 commentaires
Walter Roberson
Walter Roberson le 28 Oct 2016
Lichen WANG comments to Lamia Kasmi:
Your solution 'drawnow' really helps me. Thanks a lot.
Fiona Macfarlane
Fiona Macfarlane le 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Errorbars dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by