MATLAB: Boxplot and Dimensions Arrays

boxplotMATLAB

%msf for sample size
msfs = [0.8929, 0.8547, 0.998, 0.9506, 0.9074, 0.9074];
%msf for population
msfp = [0.9836, 0.9685, 0.9097, 0.9027, 0.8278, 0.7551, 0.8929, 0.8547, 0.998, 0.9506, 0.9074, 0.9074, 1.0291, 1.032, 1.1996, 1.1181, 0.939, 0.752, 0.762, 0.0253, 0.933, 1.073, 0.644, 0.789];
%boxplot
figure(8)
group = [ ones(size(msfs)); 2*ones(size(msfp)) ];
boxplot([msfs; msfp], group)
set(gca, 'XTixkLabel', {'group', 'population'})
So, I'm trying to plot two vectors as a boxplot side by side and I've used the above code. But when input into MATLAB I get the following error message:
Dimensions of arrays being concatenated are not consistent.
And I wasn't sure how to fix it, I was wondering if anyone would be able to help?

Best Answer

If you define your original arrays as column vectors, instead of row vectors, your code will work. Try this instead:
%msf for sample size
msfs = [0.8929, 0.8547, 0.998, 0.9506, 0.9074, 0.9074]';
%msf for population
msfp = [0.9836, 0.9685, 0.9097, 0.9027, 0.8278, 0.7551, 0.8929, 0.8547, 0.998, 0.9506, 0.9074, 0.9074, 1.0291, 1.032, 1.1996, 1.1181, 0.939, 0.752, 0.762, 0.0253, 0.933, 1.073, 0.644, 0.789]';