Azzera filtri
Azzera filtri

How to add error bar in Barchart Matlab

2 visualizzazioni (ultimi 30 giorni)
Behrad Ze
Behrad Ze il 4 Lug 2023
Risposto: Voss il 4 Lug 2023
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.

Risposta accettata

Voss
Voss il 4 Lug 2023
% 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

Più risposte (0)

Categorie

Scopri di più su Errorbars in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by