Hi Francisco,
I understand the issue you are facing. The BOXPLOT documentation states that: boxplot(X,G) specifies one or more grouping variables G, producing a separate box for each set of X values sharing the same G value or values. Grouping variables must have one row per element of X, or one row per column of X.
There are two possible scenarios for the arguments that BOXPLOT takes:
Scenario 1) First Argument to BOXPLOT function is a vector:
In this case, the second argument also has to be a vector of the same size. So for example:
>> y = randn(100,1); boxplot(y,ones(size(y)),'symbol','.')
Scenario 2) First argument to the BOXPLOT function is a matrix:
It is also intended that BOXPLOT function works if second argument is a matrix, and in that case you can give a value for each column:
>> y = randn(100,2); boxplot(y,[1 4],'symbol','.')
However, it is an edge case where y is a single-column matrix. (i.e. X = 100x1 matrix )It qualifies as a vector, so the function expects the first syntax. The reason for the failure is that there is an older syntax for BOXPLOT function which is still working:
BOXPLOT(X,NOTCH,SYM,VERT,WHIS)
When the function sees a second input that looks more like a valid NOTCH value rather than either one row per vector element or one value per matrix column and since it does not recognize that a valid value, it returns an error message.
Please note, that it requires MathWorks Account to access the link.
So, the intended current and correct syntax is to provide one grouping value per element when X is a vector.
In a situation where code may receive an X that is intended to be treated as a matrix but may just happen to have one column, you can use the syntax having the grouping variables in a cell array, for example:
>> y = randn(100,1); boxplot(y,{1},'symbol','.')
>> y = randn(100,2); boxplot(y,{1:2},'symbol','.')
Hope this helps.
Thanks
Sudhanshu Bhatt
Best Answer