Boxplot using cell array where each cell has different size

조회 수: 45 (최근 30일)
Enrico Gambini
Enrico Gambini 2021년 5월 19일
댓글: Enrico Gambini 2021년 5월 20일
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일
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
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
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)
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')

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by