Note that, since the data is random, my plot won't look the same as yours.
X2=[1.3 2.3 3.3 4.3 5.3 6.3 7.3 8.3];
boxplot(a,'positions',X1,'labels',X1,'colors','b','widths',0.25,'BoxStyle',"filled")
boxplot(b,'positions',X2,'labels',X2,'colors','r','widths',0.25,'BoxStyle',"filled")
set(gca,'xticklabel',{'#1','#2','#3','#4','#5','#6','#7','#8'})
By the way, with a little effort, you could create a grouped boxplot with one call to boxplot. You just need to set up your grouping variables.
data = reshape(data,10,16);
G = [ones(size(X1)); 2*ones(size(X1))];
boxplot(data,[x,G],"ColorGroup",G,"BoxStyle","filled",'colors',['b' 'r'])
One final comment. There is also a boxchart function which does not require any toolbox to use. It is a new function that also creates box plots, but has a slightly different syntax and appearance.
When using grouping, the inputs must be vectors. code for that might look like this. For more, see my answer here. x = ones(size(G,1),1)*X1;
boxchart(x(:),data(:),'GroupByColor',G(:))
Best Answer