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).![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1426318/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1426318/image.png)
However the thing that I am getting is like this one.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1426323/image.png)
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.
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Errorbars 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!