boxplot with vectors of different lengths???

4 views (last 30 days)
Ern V
Ern V on 14 Oct 2016
Answered: KSSV on 14 Oct 2016
Hi, i know that this is not the first time that this question is being asked, but i want to know if there is an alternative way to do this. The answers that i found is
>> 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)
But i dont find this one very practical, because if you have large number of vectors, with different lengths, you have to do
grp = [zeros(1,n1),ones(1,n2), 2*ones(1,n3), 3*ones(1,n4),...]
So how can i do the boxplot with multiple vectors with different lengths? Thank you

Answers (1)

KSSV
KSSV on 14 Oct 2016
clc; clear all ;
S = [] ; grp =[] ;
for i = 1:20
C = rand(randsample(1:100,1),1) ;
S = [S ; C] ;
grp = [grp ; i*ones(size(C))] ;
end
boxplot(S,grp)

Categories

Find more on Physics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!