Mat Ginny Vogginio
Mat Ginny Vogginio

Reputation: 57

Using boxplot with different length of vectors

Hi I try to make a boxplot for hourly values of data for differnt months. So in one diagramm I have a boxplot for January Feb March and so on... As the amount of hours of each month vary boxplot always gives me an error.

code

X=[N11(:,9) D12(:,9) J1(:,9) F2(:,9) ];
G=[1 2 3 4];
boxplot(X,G)

size of data:

J1=744

F2=624 

D12=744

N11=720

thanks matthias

Upvotes: 0

Views: 3597

Answers (2)

Shanqing Cai
Shanqing Cai

Reputation: 3876

Similar questions have been asked before. See:

http://www.mathworks.com/matlabcentral/answers/60818-boxplot-with-vectors-of-different-lengths

Basically, you put all the data in a 1-D array and use another 1-D array (of the same length) to label the groups.

Upvotes: 0

Maurits
Maurits

Reputation: 2114

You can manually append all of your data together in a single vector and then create a grouping variable g whose label indicates to which group a data point belongs on the corresponding row. For example:

A = randn(10, 1); B = randn(12, 1); C = randn(4, 1); 
g = [repmat(1, [10, 1]) ; repmat(2, [12, 1]); repmat(3, [4, 1])];
figure; boxplot([A; B; C], g);

Upvotes: 3

Related Questions