Bar(matrix) with errorbars on the same figure

Hi
I'm trying to plot bar with errorbars on the same figure. I tryed but it doesn't seem to work. Code: a=<4x4 double> = [0,1,0,0; 4,3,2,1; 2,2,1,3; 1,0,0,0] b=<4x4 double> = [0,1,0,0; 1,2,1,1; 1,1,1,2; 1,0,0,0] bar(a); hold on;errorbar(a,b,'.'); the answer is
How to put errorbar on each bar?

Risposte (1)

Star Strider
Star Strider il 30 Dic 2016
See Grouped Bar Series Xdata in 2014b. You can easily adapt Kelly’s code to your data.

4 Commenti

fu-hua yang
fu-hua yang il 2 Gen 2017
Modificato: fu-hua yang il 2 Gen 2017
Thanks! But still not succeed
My pleasure!
This works for me, and seems to produce the correct plot.
The Code:
a=[0,1,0,0;
4,3,2,1;
2,2,1,3;
1,0,0,0];
b=[0,1,0,0;
1,2,1,1;
1,1,1,2;
1,0,0,0];
ctrs = 1:4;
data = a;
figure(1)
hBar = bar(ctrs, data);
for k1 = 1:size(a,1)
ctr(k1,:) = bsxfun(@plus, hBar(1).XData, [hBar(k1).XOffset]');
ydt(k1,:) = hBar(k1).YData;
end
hold on
errorbar(ctr, ydt, b, '.r')
hold off
The Plot:
Thanks a lot!! 2014b differ 2012a but I get it now:P
My pleasure!
I assumed you were using R2014b or later. I can no longer run this code (archived from a 2014 Answer), so I will let you adapt it. The loop is different for R2014a and earlier:
load('Mean.mat') % Mean contains all mean values and consists of 5 rows
load('Stddeviation.mat')
x = [time]; % define x-axis
y = [IC1,IC2,IC3,IC4]; % define y-axis
e = [sd1,sd2,sd3,sd4,sd5,sd6]'; % define standard deviation
figure
hBars = bar(y,1.0,'grouped');
set(gca,'XTickLabel',{'Baseline','0,1','0.2','0.3','0.4','0.5'})
% set ticks and tick labels
xlabel('Time')
ylabel('Impulse')
hold on
for k1 = 1:4
hb = get(get(hBars(k1),'Children'), 'XData');
midbar = mean(hb);
errorbar(midbar, y(:,k1), e(:,k1), '.') % plotting errors
end
title('Impulse');
legend('a','b','c','d','Location','SouthEastOutside')
% put in lower right
box off
hold off

Accedi per commentare.

Tag

Richiesto:

il 30 Dic 2016

Commentato:

il 3 Gen 2017

Community Treasure Hunt

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

Start Hunting!

Translated by