How can I change the bar style in a errorbar plot?

Hi, I have a problem when I update my Matlab version from 2012b to 2014b. The problem is when I plotted any figure in Matlab 2012b I can access to any object and modify it. For now under Matlab 2014b I cannot access these objects. This is a global problem for Matlab 2014b, so I focus on a specific one:
How can I now modify the bars of the errorbar plot in order to get dashed errorbar style under Matlab 2014b. This is my code under Matlab 2012b:
hline = errorbar(x,y,L,U,'r','LineStyle','none');
hline = get(hline,'Children');
set(hline(2),'LineStyle','--');
best regards,
Kevin

 Accepted Answer

In HG2 (in R2014b+), 'Chlidren' no longer exist.
This will work:
hline = errorbar(x,y,L,U,'r','LineStyle','none');
set(hline,'LineStyle','--');
as will this:
hline = errorbar(x,y,L,U,'r','LineStyle','none');
hline.LineStyle = '--';

4 Comments

Kevin Dupraz’s ‘Answer’ moved here...
Thanks for your answer, but I already tested this solution and it only change the line which passes through the mean points. It does not change the errorbar style itself. The command line:
hline(2)
of my code take the errorbar handle (not the average line handle). But this handle does not exist any more in Matlab 2014b and it seems that this "line" errorbar cannot be accessible.
Correct. That functionality has been lost in HG2. I couldn’t even find a fix for it in Undocumented MATLAB. That’s the reason I still have R2014a installed on my system. I can still use the functionality lost in HG2, that I need.
This will plot them without the horizontal end bars (that was the original idea behind this code snippet), but you can specify the line style of the error bars:
N = 20;
x = linspace(0, 2*pi, N); % Create Data
y = sin(x).^2; % Create Data
erbar = randn(1, N); % Create Error Bars
figure(1)
plot(x, y)
hold on
plot([x; x], [y-erbar; y+erbar], '--r')
hold off
grid
legend('Data', 'Error')
Ok great this makes the job partially but it is sad that the functionality was removed.
I agree. I believe functionality that was easy in HG1 is being gradually restored to HG2, and some new necessary functionality is being added, but it is taking time.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!