Boxplot groups by mask set

조회 수: 3 (최근 30일)
Sven
Sven 2011년 4월 15일
I have a vector of data, and a set of masks defining my (possibly overlapping) groups:
data = rand(100,1)
grpMasks = [(1:100)'<25, (1:100)'<60&(1:100)'>10, (1:100)'>40, rand(100,1)>0.5]
So my data is 100-by-1, I have 4 groups in a 100-by-4 logical mask. I want to make a boxplot with 4 boxes, 1 per mask.
boxplot(data, grpMasks)
Makes N boxes, where N is the number of unique row combinations in grpMasks.
I know that I can loop from 1 to 4, make a single boxplot and then shift each box's X-location, but I feel like that's unnecessarily messy. I've got my data, I've got a format of my groups. Can boxplot handle this form of grouping?

채택된 답변

Sven
Sven 2011년 4월 15일
Ah! Here's my solution. Repeat the data for as many groups as you have, and then NaN out the data not belonging to each group:
data = rand(100,1);
grpMasks = [(1:100)'<25, (1:100)'<60&(1:100)'>10, (1:100)'>40, rand(100,1)>0.5];
numGrps = size(grpMasks,2);
allData = data * ones(1,numGrps);
allData(~grpMasks) = nan;
boxplot(allData);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by