필터 지우기
필터 지우기

How to add error bar in Barchart Matlab

조회 수: 2 (최근 30일)
Behrad Ze
Behrad Ze 2023년 7월 4일
답변: Voss 2023년 7월 4일
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