Bar(matrix) with errorbars on the same figure

조회 수: 9 (최근 30일)
fu-hua yang
fu-hua yang 2016년 12월 30일
댓글: Star Strider 2017년 1월 3일
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?

답변 (1개)

Star Strider
Star Strider 2016년 12월 30일
See Grouped Bar Series Xdata in 2014b. You can easily adapt Kelly’s code to your data.
  댓글 수: 4
fu-hua yang
fu-hua yang 2017년 1월 3일
Thanks a lot!! 2014b differ 2012a but I get it now:P
Star Strider
Star Strider 2017년 1월 3일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Errorbars에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by