Borrar filtros
Borrar filtros

how to plot a grouped bar chart with categories and error bars

8 visualizaciones (últimos 30 días)
sophp
sophp el 23 de Abr. de 2020
Comentada: sophp el 24 de Abr. de 2020
I want to plot a grouped bar chart with catogories and error bars. However, the following code returns an error: "The length of X must match the number of rows of Y." However, I have checked this and X does match Y.
x=categorical({'Q3';'Q6';'Q10';'Q15';'Q30';'Q50'});
y=[2.891586318,1.99422657,1.907652812,4.71298388,6.007681496,6.718181667;3.229392123,3.36482536,4.089746011,5.204662107,6.761377397,7.978099976];
errorplus=[0.167797,0.314574,0.081018,0,0.116596,0;0,0.173132,0,0.231752,1.15677,1.204734];
errorminus=errorplus;
figure;
bar(x,y);
hBar = bar(y, 0.8);
for k1 = 1:size(y,2)
ctr(k1,:) = bsxfun(@plus, hBar(k1).XData, hBar(k1).XOffset');
ydt(k1,:) = hBar(k1).YData;
end
hold on
errorbar(ctr, ydt, errorplus, '.r')
hold off
ylabel('Angle Values [°]','FontSize',18)
set(gca,'linewidth',2,'FontSize',14)
ylim([0 10]);
set(gca,'XTickLabel',x)

Respuesta aceptada

Mehmed Saad
Mehmed Saad el 24 de Abr. de 2020
Take transpose of y
  5 comentarios
Mehmed Saad
Mehmed Saad el 24 de Abr. de 2020
your matlab version? mine is R2019a and it is working
sophp
sophp el 24 de Abr. de 2020
Ah yes sorry Muhammad, it works now after I cleared the command window

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Modify Image Colors en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by