Boxplot using cell array where each cell has different size

42 visualizzazioni (ultimi 30 giorni)
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!

Risposta accettata

dpb
dpb il 19 Mag 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.
  3 Commenti
dpb
dpb il 19 Mag 2021
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.

Accedi per commentare.

Più risposte (1)

Adam Danz
Adam Danz il 19 Mag 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')

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by