MATLAB: Boxplot with vectors of different lengths

boxplotdifferent lengthvector

Hi MATLAB folks,
I am wondering how I can boxplot two column matrices with different lengths, e.g.
c_1=rand(1,20);
c_2=rand(1,100);
how I can do
boxplot(C);
where:
C=cell(1,2);
C{1}=c_1(:);
C{2}=c_2(:);
Is there any solution to that?
Many thanks in advance, -V

Best Answer

BOXPLOT works with grouping variables, so you can manually append all of your data together and then create a grouping variable that lets boxplot know which belongs to first and which for second. Take a look at the example below:
>> c_1=rand(1,20);
>> c_2=rand(1,100);
>> C = [c_1 c_2];
>> grp = [zeros(1,20),ones(1,100)];
>> boxplot(C,grp)
Related Question