Azzera filtri
Azzera filtri

How to make a grouped boxplot of measurements data from five days?

1 visualizzazione (ultimi 30 giorni)
Hi,
I have a 46x5 matrix with measurement data from 46 points taken on five days, called MyData.
The 46 measurement points belong to three groups. They are saved in a 46x1 vector called Site, with values 1, 2 or 3 representing the three groups.
I'm trying to create a grouped boxplot using:
MyData = rand(46,5);
Site = randi([1 3],46,1);
boxplot(MyData,Site);
but I'm getting an error:
Error using boxplot>straightenX (line 970)
G must be the same length as X or the same length as the number of columns in X.
Error in boxplot (line 274)
[xDat,gDat,origRow,xlen,gexplicit,origInd,origNumXCols] = straightenX(x,g);
G and X actually do have the same length (46), but I assume Matlab doesn't like the fact that the number of columns in X is larger than one.
Does any of you know how to solve it? My goal is to make a boxplot similar to this (just made in Powerpoint:)

Risposta accettata

Corymbiamaculata
Corymbiamaculata il 30 Ott 2019
I found the answer myself; updating in case someone has a similar problem.
MyData = rand(46,5);
Site = randi([1 3],46,1);
MyDataNew = reshape(MyData,size(MyData,1)*size(MyData,2),1); % reshape into one column
MeasureDay = repelem(1:5,[size(MyData,1)],[1]); % new variable with values representing measurement days
MeasureDay = reshape(MeasureDay,size(MeasureDay,1)*size(MeasureDay,2),1); % reshape into one column
Site = repmat(Site,5,1); % reshape into one column
boxplot(MyDataNew,[Site,MeasureDay]); % two grouping variables used together

Più risposte (0)

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by