How to add error bar in Barchart Matlab

2 次查看(过去 30 天)
Dear All,
I am trying to plot barcharts with error bars in Matlab using the code below. However, I cannot mix two groups of data together. The plot which I want should be like the first attached plot (with errorbars).
However the thing that I am getting is like this one.
In the second graph, the graphs are being separated into two groups. I am using the code below:
% data
model_series = [5815 2178 4898 1265 773 833 232 2190 189; 6246 0 3540 1164 421 0 90 672 189];
model_error = [872 326 735 189 116 124 35 329 28; 936 0 531 175 63 0 14 101 20];
b = bar(model_series, 'grouped');
hold on
[ngroups,nbars] = size(model_series);
x = nan(nbars, ngroups);
for i = 1:nbars
x(i,:) = b(i).XEndPoints;
end
errorbar(x',model_series,model_error,'k','linestyle','none');
hold off
I would be very thankful, if any could help me with this problem.

采纳的回答

Voss
Voss 2023-7-4
% data
model_series = [5815 2178 4898 1265 773 833 232 2190 189; 6246 0 3540 1164 421 0 90 672 189];
model_error = [872 326 735 189 116 124 35 329 28; 936 0 531 175 63 0 14 101 20];
b = bar(model_series.', 'grouped');
hold on
[ngroups,nbars] = size(model_series);
x = nan(nbars, ngroups);
for i = 1:ngroups
x(:,i) = b(i).XEndPoints;
end
errorbar(x,model_series.',model_error.','k','linestyle','none');
hold off

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Errorbars 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by