putting error bars on bar plot?
195 ビュー (過去 30 日間)
古いコメントを表示
Hello!
I have a mean of subjects bar plot, specifically a horizontal bar plot (barh), and I want to add error bars to the the bar plot and plot it against categorical data. I have calculated the STD:
values:
std = 34x1 double
mean = 34x1 double
x = 1x34 categorical
std = std(matrix, 0, 2)
barwitherr(std, 1:length(x), mean_matrix)
The plot runs, but doesn't add error bars.
I am getting the error:
Undefeined function barwitherr for input arguments of type double.
Can you help me?
0 件のコメント
採用された回答
Star Strider
2021 年 11 月 9 日
I do not remember when ‘XEndPoints’ and ‘YEndPoints’ were introduced (and I am not able to find it in the documentation), so I included two options —
x = categorical({'a','b','c'});
y = [75.8 78.05; 81 80.30; 91 80.78];
err = rand(size(y))*10;
figure
b = bar(x,y);
hold on
for k = 1:numel(b) % Recent MATLAB Versions
xtips = b(k).XEndPoints;
ytips = b(k).YEndPoints;
errorbar(xtips,ytips,err(:,k), '.g', 'MarkerSize',0.1)
end
hold off
figure
b = bar(y);
for k = 1:numel(b) % Earlier MATLAB Versions
ctr(k,:) = bsxfun(@plus, b(k).XData, [b(k).XOffset]');
ydt(k,:) = b(k).YData;
end
hold on
errorbar(ctr, ydt, err.', '.g', 'MarkerSize',0.1)
hold off
set(gca,'XTickLabel',x)
This is a general solution, using single or grouped bar plots, and adapts to the size of ‘y’. Choose the approach that works, depending on the available MATLAB version/release.
.
2 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Distribution Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!