Boxplot using cell array where each cell has different size
44 次查看(过去 30 天)
显示 更早的评论
Hello to everyone!
I would like to obtain a single graph with boxplots using a 1x40 cell array, each cell has a different number of elements (vectors of type double) and represents observations for a single year .
I would like to group the boxplots from year 1981 to 2020 in a single graph.
Hope that my question is clear, thank you!
0 个评论
采纳的回答
dpb
2021-5-19
Fill each cell with NaN to the same size vector and then convert to an array. boxplot will ignore the NaN missing value indicators.
3 个评论
dpb
2021-5-19
boxplot() is written to take a double array, not cell array, so not simply, no. It's easy enough to just augment the data and the result is/will be the same.
The alternative is to add each on top of an existing axes; the code to do that would be more complex than just rounding out the existing data.
更多回答(1 个)
Adam Danz
2021-5-19
boxplotGroup from the file exchange will accept the cell array you described.
c = arrayfun(@(i){rand(randi([5,20]),1)},1:40)
years = compose('%d',1981:2020)
boxplotGroup(c, years)
xlabel('year')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/622993/image.png)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axis Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!