Bar Graph with Error bars

10 Ansichten (letzte 30 Tage)
Mohit Agnihotri
Mohit Agnihotri am 11 Aug. 2015
Kommentiert: Star Strider am 11 Aug. 2015
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.

Antworten (1)

Star Strider
Star Strider am 11 Aug. 2015
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 Kommentare
Star Strider
Star Strider am 11 Aug. 2015
Mohit Agnihotri’s ‘Answer’ moved here...
I am using R2015a, to be precise: 8.5.0.197613 (R2015a)
Star Strider
Star Strider am 11 Aug. 2015
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

Melden Sie sich an, um zu kommentieren.

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by