Why doesn't boxplot work with cells in a table? 'X' parameter must be a numeric vector or matrix.
3 views (last 30 days)
Show older comments
tldr: Is there some minor edit my code for boxplot to read the data in the cell (e.g. wrap in {} or use (:)), or must I change the table to explicitly put each datum in its own row with its own DoseInterval specification?
~~~
If I create a table that neatly stores data using cells, MATLAB insists the boxplot input data be a numeric vector or matrix. Why doesn't it use the data in the table's cell? Will this feature be included in a future release?
The table:
Planned = cell(9,1); Planned(:) = {10*rand(1,100)};
Measured = cell(9,1); Measured(:) = { rand(1,100)};
datatoplot = table(Planned,Measured,{'1-2';'2-3';'3-4';'4-5';'5-6';...
'6-7';'7-8';'8-9';'9-10'},'VariableNames',...
{'Planned' 'Measured' 'DoseIntervals'})
The attempted boxplot:
figure
boxplot({datatoplot.Planned},datatoplot.DoseIntervals,'Colors','r')
hold on
boxplot(datatoplot.Measured,datatoplot.DoseIntervals,'Colors','b')
hold off
The error:
Error using boxplot>straightenX (line 895)
'X' parameter must be a numeric vector or matrix.
Error in boxplot (line 273)
[xDat,gDat,origRow,xlen,gexplicit,origInd,origNumXCols] = straightenX(x,g);
Looking at the straightenX function in the boxplot script, it appears to assume the input is a vector or matrix, as the error message indicates. Will it be coded to check if it's a cell and read the data in the cell in a future release? Is there some easy way to edit my code to read the data in the cell, or must I change the table to explicitly put each value in its own row with its own DoseInterval specification?
0 Comments
Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!