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

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!

Respuestas (1)

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 comentarios

car
car el 28 de Mayo de 2018
Absolutely beautiful, thank you!!
You are welcome.
Thanks a lot - very helpful.

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Objects en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

car
el 28 de Mayo de 2018

Comentada:

el 20 de Sept. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by