Hello, I am struggling with a Boxplot using multigroup. My data is formatted as below. I like to apply a grouping variable for the columns and also for the rows. In this case, the 3 values per column belong to an observed, simulated and expected value. Within the rows, there are different settings. This is a minimal working example, but I really don't understand what the error is about, because all rows/columns match from my point of view.
But I get the error:
Error using boxplot>convertToCellarrayOfColumnVectors (line 1082)
All columns in 'G' must have the same length.
data = rand(3,10);
groupH = [0,1,0,3,1,3,0,1,1,0];
groupV = repmat([0;1;2],1,10);
boxplot(data, {groupH, group})
The Output as desired as having 3 Boxplots for same category out of h with 3 different classes from groupV directly beside. I found the following example after posting, which is quite similar, but I am really confused adapting this code for my purposes.

6 Kommentare

KALYAN ACHARJYA
KALYAN ACHARJYA am 25 Sep. 2018
Can you share the code/representational code??
jonas
jonas am 25 Sep. 2018
How do you call Boxplot?
Jan Maluche
Jan Maluche am 26 Sep. 2018
Sorry, I don't know why I forget to post the line. Edited the code right now.
jonas
jonas am 26 Sep. 2018
Can you explain what your desired output is? How many boxes are you looking for?
Jan Maluche
Jan Maluche am 26 Sep. 2018
Updated the question with the desired output. For this case I am expecting 30 boxes.
jonas
jonas am 26 Sep. 2018
Okay I see the problem. Will post an answer shortly.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

jonas
jonas am 26 Sep. 2018
Bearbeitet: jonas am 26 Sep. 2018

0 Stimmen

I found some issues with your approach. Most importantly, the number of rows in the matrix is supposed to represent the number of data points per series, which are then later visualized by a single box. Perhaps you understood this already, but each series in your example had only a single point, which was confusing to me. I have changed this to 100 pts per series of data.
This example goes on to show how to group 30 series of data in 10 different categories [1st 1st 1st 2nd 2nd 2nd ... 10th 10th 10th], with each category having three different types of series [1st 2st 3rd].
% Some data
data = rand(100,30); % 30 series, 100 pts in each
% 10 categories
% a trick to get [0 0 0 1 1 1 2 2 2 ... 9 9 9]
groupH = repmat([0:9],1,3);
groupH = reshape(groupH,10,3)'
groupH = groupH(:)
% three types of data series
groupV = repmat([0 1 2],1,10); %every third series is of the same type
% plot
boxplot(data,{groupH,groupV},'factorgap',[5 2])
.
You can see the two grouping vectors in the xlabels. Note that the grouping [0 1 2...] is redundant in this example. However, if your data is not nicely organized, then two grouping variables can be useful.

2 Kommentare

Jan Maluche
Jan Maluche am 26 Sep. 2018
Thank you, this is really helpful and totally adresses my problem.
jonas
jonas am 26 Sep. 2018
Happy to help! Please mark the answer as accepted if your issue is resolved :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Version

R2015b

Gefragt:

am 25 Sep. 2018

Kommentiert:

am 26 Sep. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by