How to barplot with standard deviation?

92 views (last 30 days)
I've got following code so far:
if true
% code
end
load('Mean.mat') % Mean contains all mean values and consists of 5 rows
x = [time]; % define x-axis
y = [IC1,IC2,IC3,IC4]; % define y-axis
figure;
hBars = bar(y,1.0); % create bar plot with y;
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;
load('standarddev.mat') % standarddev contains all calculated standard deviation and consists of 5 %rows
std = [sd1,sd2,sd3,sd4,sd5]; % define y-axis
errorbar(x,y,std);
title('Impulse');
legend('a','b','c','d','Location','SouthEastOutside')
% put in lower right
The plot itself works fine. I'd like to include the errorbars for the standard deviation as well but that unfortunately doesn't work at the moment. I've already had a look at the MATLAB Documentation Center bt without success.
Any help would be appreciated.

Accepted Answer

Star Strider
Star Strider on 9 Jul 2014
We did this a few weeks ago in How to add errorbars. Be sure to read dpb’s answer as well.

More Answers (2)

Pinga
Pinga on 10 Jul 2014
Thank you, I should have done that. In the meanwhile I did but it somehow still doesn't work. Only about the half of all errorbars are plotted and still not placed in the center top of the bars (see attachment).
Since I'm new to MATLAB, I would thankful for every suggestion on my code.
if true
% code
end
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 = [std1,std2,std3,std4,std5,std6]; % define standard deviation
figure;
hBars = bar(y,1.0,'gropued');
set(gca,'XTickLabel',{'Baseline','0,1','0.2','0.3','0.4','0.5'});
% set ticks and tick labels
xlabel('Time');
ylabel('Impulse');
hold all;
for i = 1:6;
j = 1:4;
x = -0.5 + i + 1/5 *j;
errorbar(x,y,(j,i),e(j,i),'.'); % plotting errors
end
title('Impulse');
legend('a','b','c','d','Location','SouthEastOutside')
% put in lower right
box off;
hold off;
  19 Comments
Pinga
Pinga on 21 Jul 2014
Great, thank you for everything!
Star Strider
Star Strider on 21 Jul 2014
My pleasure!
I’m sure with TMW’s help, you’ll get it sorted!

Sign in to comment.


Pinga
Pinga on 10 Jul 2014
What I've tried is to switch the columns/rows since the last plot only showed four groups of errorbars. But that didn't solve the problem. I left the values for the standard deviation in this switched order.
That would be great, if anyone could help me - I've been trying for some days now to only plot these data.

Community Treasure Hunt

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

Start Hunting!