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 Center および File ExchangeAnnotations についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by