Box plot for each cell of a cell array all on one figure

조회 수: 5 (최근 30일)
car
car 2018년 5월 28일
댓글: Narayanan Krishnamurthi 2021년 9월 20일
I want to make a figure of box plots where each box corresponds to the data in one cell of a cell array. Generally, this will mean about 14 boxes in one figure. I can easily make on box plot from one cell of data using
boxplot(tmp_indiv{1,1})
but because the length of my cell arrays are constantly changing, I cannot use something like
boxplot(top_five_precip_a{:})
I have far too many cell arrays to do this individually. Furthermore, I want to change the whisker length so that all box plots will have whiskers to the 95th percentile as opposed to the default, which I believe I've done using
boxplot(tmp_indiv{1,1}, 'whisker', 0.7193)
but I'm not 100% sure that its correct.
Any help would be greatly appreciated. Thanks!

답변 (1개)

Ameer Hamza
Ameer Hamza 2018년 5월 28일
Try this
% creating sample dataset
tmp_indiv{1} = 1:10;
tmp_indiv{2} = 11:30;
tmp_indiv{3} = 31:40;
y = num2cell(1:numel(tmp_indiv));
x = cellfun(@(x, y) [x(:) y*ones(size(x(:)))], tmp_indiv, y, 'UniformOutput', 0); % adding labels to the cells
X = vertcat(x{:});
boxplot(X(:,1), X(:,2))
  댓글 수: 3
Ameer Hamza
Ameer Hamza 2018년 5월 28일
You are welcome.
Narayanan Krishnamurthi
Narayanan Krishnamurthi 2021년 9월 20일
Thanks a lot - very helpful.

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

카테고리

Help CenterFile Exchange에서 Graphics Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by