Bar Graph with Error bars

조회 수: 1 (최근 30일)
Mohit Agnihotri
Mohit Agnihotri 2015년 8월 11일
댓글: Star Strider 2015년 8월 11일
Hi, I am trying to draw bar graphs with corresponding error bars, but I have been failing miserably and thus I seek your help.
Following are the data characteristics: Input data: 3x3 matrix Input Error data: 3x3 matrix
Attempts:
Data = rand(3,3);
Error = rand(3,3);
figure;
hold on;
bar(1:length(Data(1,:)),Data)
errorbar(1:length(Data(1,:)),Data,Error)
hold off;
but this produces error.

답변 (1개)

Star Strider
Star Strider 2015년 8월 11일
It depends on whether you are using R2014a or earlier, or R2014b or later. See this search for a method that works for you.
  댓글 수: 2
Star Strider
Star Strider 2015년 8월 11일
Mohit Agnihotri’s ‘Answer’ moved here...
I am using R2015a, to be precise: 8.5.0.197613 (R2015a)
Star Strider
Star Strider 2015년 8월 11일
Here is code from the archives. Tweak it to your needs:
y = [212206000000 229040000000 39312320000; 119783500000 169247500000 128418300000 ; 211838000000 706581300000 85349300000];
hBar = bar(y);
set(gca,'XTickLabel', {'300 ','350 ','400 '})
legend('C','S','T', 'Location','N')
grid on
ylabel('N/m^{2}')
xlabel ('\mum')
colormap summer
for k1 = 1:size(hBar,2)
ctr(k1,:) = bsxfun(@plus, hBar(k1).XData, [hBar(k1).XOffset]'); % Centres Of Bar Groups
ydt(k1,:) = hBar(k1).YData; % Y-Data Of Bar Groups
end
hold on
for k1 = 1:size(hBar,2)
errorbar(ctr(k1,:), ydt(k1,:), ones(size(ydt(k1,:)))*0.1.*ydt(k1,:), '.r') % Plot 10% Error Bars
end
hold off

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

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by