Azzera filtri
Azzera filtri

Mean, Max and Min of Structured Cell array

3 visualizzazioni (ultimi 30 giorni)
Hi all, I have a structured cell array where I need to compute the mean of each cell from column 4. Column 3 contains the name of the data (repeated for number of days 31, 29 etc.). At the end I would like to display the results as name (3rd column one value) , Average, Min and Max of each cell of 4th column data. Any help (sample example) in this regard is highly appreciated. For your reference I have attached the picture.

Risposta accettata

Matt J
Matt J il 8 Apr 2021
Modificato: Matt J il 8 Apr 2021
You should first convert everything to table form.
Column3={{'dog';'dog';'dog'},{'cat';'cat'}}; %Original data
Column4={[1;2;3], [4;5]};
Column3=string( vertcat(Column3{:}) );
Column4=vertcat( Column4{:} );
T=table(Column3,Column4,'VariableNames',{'Names','Data'})
T = 5×2 table
Names Data _____ ____ "dog" 1 "dog" 2 "dog" 3 "cat" 4 "cat" 5
From that point on, it all becomes much easier:
Means = varfun(@mean,T,'GroupingVariables','Names')
Means = 2×3 table
Names GroupCount mean_Data _____ __________ _________ "cat" 2 4.5 "dog" 3 2
Maxs= varfun(@max,T,'GroupingVariables','Names')
Maxs = 2×3 table
Names GroupCount max_Data _____ __________ ________ "cat" 2 5 "dog" 3 3
  14 Commenti
Matt J
Matt J il 10 Apr 2021
But I just showed you that it works with @(x) x(1)
Ganesh Naik
Ganesh Naik il 10 Apr 2021
Hi Matt, thanks. I have managed to get it work.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by