Bar graphs with two sets of different sizes

조회 수: 13(최근 30일)
Flo 2016년 5월 5일
편집: Flo 2016년 5월 6일
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.
h(:,1)=one;
h(:,2)=two;
[y,x]=hist(h);
bar(x,y, 'group');
title('Area comparison');
xlabel('Area'); % x-axis label
ylabel('Frequency'); % y-axis label
legend('XZ','YZ');
saveas(gcf,mypath);
one and two are my datasets.
would you know if there is a way of doing through matlab?
Flo

댓글을 달려면 로그인하십시오.

채택된 답변

Mike Garrity 2016년 5월 5일
One simple way is this:
none = length(one);
ntwo = length(two);
h = nan(max(none,ntwo),2);
h(1:none,1)=one;
h(1:ntwo,2)=two;
[y,x] = hist(h);
bar(x,y, 'group');
댓글 수: 1표시숨기기 없음
Flo 2016년 5월 6일
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? 댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!