Bar graphs with two sets of different sizes

23 visualizaciones (últimos 30 días)
Flo el 5 de Mayo de 2016
Editada: Flo el 6 de Mayo de 2016
Hi everyone,
I am trying to plot one bar graph with using twos sets of different sizes.
The following code works fine if the datasets are equal in size, but doesnt if not.
bar(x,y, 'group');
title('Area comparison');
xlabel('Area'); % x-axis label
ylabel('Frequency'); % y-axis label
one and two are my datasets.
would you know if there is a way of doing through matlab?
Thanks for your help :)

Respuesta aceptada

Mike Garrity
Mike Garrity el 5 de Mayo de 2016
One simple way is this:
none = length(one);
ntwo = length(two);
h = nan(max(none,ntwo),2);
[y,x] = hist(h);
bar(x,y, 'group');
  1 comentario
Flo el 6 de Mayo de 2016
Editada: Flo el 6 de Mayo de 2016
Thank you Mike.
It seems to work fine, but for one of my calculation I get one really weird result. At the bin number 160 the blue bar seems to reach to top of the graph. do you think it is due to the code?

Iniciar sesión para comentar.

Más respuestas (0)


Más información sobre 2-D and 3-D Plots 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