필터 지우기
필터 지우기

plotting multiple boxplots in the same figure window

조회 수: 285 (최근 30일)
Jenny
Jenny 2012년 11월 17일
댓글: Seth DeLand 2022년 5월 25일
I have 10 vectors of temperature data, all different lengths, that I want to make boxplots of and plot them all in the same figure window. How do I do this?

답변 (3개)

Tom Lane
Tom Lane 2012년 11월 19일
Here's how to do that with three vectors of different lengths:
x1 = rand(10,1); x2 = 2*rand(15,1); x3 = randn(30,1);
x = [x1;x2;x3];
g = [ones(size(x1)); 2*ones(size(x2)); 3*ones(size(x3))];
boxplot(x,g)
  댓글 수: 6
Gabriel Apaza
Gabriel Apaza 2021년 5월 5일
matlab's notation is so incredibly non user friendly it blows my mind
Seth DeLand
Seth DeLand 2022년 5월 25일
Just a note that as of R2020a this can also be accomplished using the boxchart function in MATLAB. boxplot is part of Statistics and Machine Learning Toolbox.

댓글을 달려면 로그인하십시오.


Matt Learner
Matt Learner 2018년 3월 25일
편집: Matt Learner 2018년 3월 25일
A = [16 20 15 17 22 19 17]';
B = [22 15 16 16 16 18]';
C = [23 9 15 18 13 27 17 14 16 15 21 19 17]';
group = [ ones(size(A)); 2 * ones(size(B)); 3 * ones(size(C))];
figure
boxplot([A; B; C],group)
set(gca,'XTickLabel',{'A','B','C'})
  댓글 수: 4
TESFALEM ALDADA
TESFALEM ALDADA 2021년 10월 28일
@Matt Learner Thank you for your answer. I was having the same problem. For the above example they it has only three variables (A, B,C), but what will happen if it has 1000 variables, are we going to type all in the group?
I ask any robest way to do this for longer data.
Peanut
Peanut 2022년 1월 20일
You would store the variables in a structure, where each field is a variable. Then you would loop through the fields, vertically concatenating each one.
e.g.
s.A = rand(10,1);
s.B = rand(15,1);
s.C = rand(20,1);
allData = [];
allCats = [];
allFields = string(fieldnames(s))
for iField = 1:length(allFields)
allData = [allData;s.(allFields(iField))];
allCats = [allCats,repelem(allFields(iField),length(s.(allFields(iField))));]
end
boxplot(allData,allCats)

댓글을 달려면 로그인하십시오.


Akiva Gordon
Akiva Gordon 2012년 11월 17일
Are you familiar with the SUBPLOT function? This may be what you are looking for…

Community Treasure Hunt

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

Start Hunting!

Translated by