# Boxplot using cell array where each cell has different size

52 views (last 30 days)
Enrico Gambini on 19 May 2021
Commented: Enrico Gambini on 20 May 2021
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 on 19 May 2021
Fill each cell with NaN to the same size vector and then convert to an array. boxplot will ignore the NaN missing value indicators.
Enrico Gambini on 19 May 2021
Ok thank you!

Adam Danz on 19 May 2021
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')
Enrico Gambini on 20 May 2021
Thank you a lot!!!

R2021a

### Community Treasure Hunt

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

Start Hunting!