# Plotting multiple box plots on same graph with same size vector?

1 view (last 30 days)
Matthew Peoples on 15 Apr 2021
Edited: ANKUR KUMAR on 15 Apr 2021
Hi everyone!
I've run into a strange issue. I have 5 1x60 double arrays that I am trying to plot boxplots of (5 boxplots on the same graph).
num_non_grey_pix_each_cat %1×5 cell array - each cell is 1x60
vects = [cell2mat(num_non_grey_pix_each_cat{1})]; % I tried just trying to plot 2
vects2 =[cell2mat(num_non_grey_pix_each_cat{2})];
vects = [vects; vects2];
figure;
boxplot(vects);
Trying to plot one plot works out fine, but then adding the second creates 60 boxplots? I'm very confused - i basically want five of the first plot on the one graph. Thank you so much!

ANKUR KUMAR on 15 Apr 2021
Edited: ANKUR KUMAR on 15 Apr 2021
As you have not provided the exact data, I am generating just the random data.
col=@(x)reshape(x,numel(x),1);
boxplot2=@(C,varargin)boxplot(cell2mat(cellfun(col,col(C),'uni',0)),...
cell2mat(arrayfun(@(I)I*ones(numel(C{I}),1),col(1:numel(C)),'uni',0)),varargin{:});
A={randi(25,1,100),randi(25,1,60),randi(25,1,60),randi(25,1,60),randi(25,1,60)}
A = 1×5 cell array
{[25 12 3 14 2 23 6 20 1 19 9 19 19 13 8 15 12 23 5 21 16 7 8 12 23 20 16 7 5 22 7 8 21 12 17 19 17 25 8 23 10 23 9 21 20 2 4 8 11 11 16 18 1 22 16 9 6 9 5 21 13 21 7 10 3 17 11 21 8 13 10 11 3 14 20 22 7 4 3 23 11 12 6 23 2 11 2 18 6 19 8 18 3 13 9 8 14 5 6 5]} {[22 6 21 12 21 20 22 7 6 18 23 22 6 14 25 5 16 4 15 2 5 13 3 5 8 25 14 20 4 20 25 20 21 22 16 8 24 22 25 6 1 25 5 11 2 11 9 18 13 25 20 21 10 25 23 1 10 1 9 2]} {[2 25 9 12 21 13 3 9 10 5 18 8 17 6 8 10 4 14 4 12 7 14 13 22 1 13 12 8 12 15 22 5 18 20 4 14 13 14 19 9 1 6 19 13 24 13 12 6 5 18 17 13 11 2 10 15 3 25 9 15]} {[3 5 16 12 16 21 13 23 3 21 8 13 24 14 10 12 13 5 12 11 17 19 22 12 17 11 5 9 17 11 5 21 3 4 19 9 16 15 17 9 25 2 10 6 17 10 25 11 14 22 3 25 23 5 20 9 19 22 24 16]} {[19 24 8 18 6 22 3 21 21 6 19 15 7 17 2 4 19 19 20 7 5 23 4 14 20 17 21 12 1 21 2 14 16 12 8 9 5 23 14 14 2 15 8 7 2 6 9 3 12 16 14 18 2 5 13 16 1 9 10 12]}
boxplot2(A)
Reference: