How to sort a boxplot in a precise order with data from a table?

조회 수: 2 (최근 30일)
Christophe KInnard
Christophe KInnard 2018년 8월 8일
I have to produce a boxplot out of a table sorted in a precise order (descend according to the median of NDVI for each category of Geo). My table has 16 columns and 1 846 150 rows. Out of this data I have 2 variables (column 15 (Geo) and 16 (NDVI)) from which I'd like to create a boxplot. Column 15 (Geo) is a categorical array. Column 16 (NDVI) is double. I tried these scripts to obtain the correct order, without any success.
I tried: statarray1 = grpstats(T10_z,'Geo','median','DataVars', 'NDVI');
[~,indT10] = sortrows(statarray1,{'median_NDVI','Geo'},'descend');
figure; boxplot(T10_z.NDVI,T10_z.Geo,'GroupOrder', indT10)
the error message is: Error using boxplot>parseArgs (line 681). The 'grouporder' parameter value must be a character array or a cell array of character vectors.
Error in boxplot (line 256) = parseArgs(varargin);
I tried:
geo10 = T10_z{:,15};
ndvi10 = T10_z{:,16};
geo10 = double(geo10);
topo10 = [ndvi10 geo10];
medians = grpstats(topo10(:,1),topo10(:,2));
[~,ind10] = sort(medians, 'descend');
ndvi10 = ndvi10(ind10);
figure(1); boxplot(ndvi10,geo10)
the error message is: Error using boxplot>straightenX (line 923) G must be the same length as X or the same length as the number of columns in X.
Error in boxplot (line 273) [xDat,gDat,origRow,xlen,gexplicit,origInd,origNumXCols] = straightenX(x,g);
I also found on the internet a script that is supposed to help, but was unable to see if it does what I want as the error message pop out at the 3rd line (* * *) and says: "Undefined function 'accumarray' for input arguments of type 'categorical'."
geo10 =T10_z{:,15};
ndvi10 = T10_z{:,16};
[~,indX] = sort(accumarray(geo10.',ndvi10,[ ],@median)); * * *
ord1 = sortrows([1:max(geo10)).' indX],2);
a = ord1(:,1);
b = histcounts(geo10);
idx(cumsum([1 b(b>0)])) = 1;
c = a(cumsum(idx(1:find(idx,1,'last')-1)));
Data_Corrected_1 = sortrows([c geo10.' ndvi10.'],1);
Thank you in advance for your help!

답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by