Boxplot using cell array where each cell has different size

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!

 채택된 답변

dpb
dpb 2021년 5월 19일

2 개 추천

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

So there's no way to obtain the boxplot with different sizes in the cell array?
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.
Ok thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

boxplotGroup from the file exchange will accept the cell array you described.
c = arrayfun(@(i){rand(randi([5,20]),1)},1:40)
c = 1×40 cell array
{18×1 double} {8×1 double} {9×1 double} {8×1 double} {16×1 double} {14×1 double} {12×1 double} {12×1 double} {13×1 double} {19×1 double} {16×1 double} {9×1 double} {18×1 double} {11×1 double} {9×1 double} {12×1 double} {16×1 double} {15×1 double} {9×1 double} {14×1 double} {10×1 double} {9×1 double} {17×1 double} {5×1 double} {20×1 double} {6×1 double} {10×1 double} {10×1 double} {8×1 double} {12×1 double} {7×1 double} {13×1 double} {10×1 double} {11×1 double} {11×1 double} {18×1 double} {17×1 double} {15×1 double} {9×1 double} {5×1 double}
years = compose('%d',1981:2020)
years = 1×40 cell array
{'1981'} {'1982'} {'1983'} {'1984'} {'1985'} {'1986'} {'1987'} {'1988'} {'1989'} {'1990'} {'1991'} {'1992'} {'1993'} {'1994'} {'1995'} {'1996'} {'1997'} {'1998'} {'1999'} {'2000'} {'2001'} {'2002'} {'2003'} {'2004'} {'2005'} {'2006'} {'2007'} {'2008'} {'2009'} {'2010'} {'2011'} {'2012'} {'2013'} {'2014'} {'2015'} {'2016'} {'2017'} {'2018'} {'2019'} {'2020'}
boxplotGroup(c, years)
xlabel('year')

카테고리

도움말 센터File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2021년 5월 19일

댓글:

2021년 5월 20일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by