Mean of a 3D struct with 6 fields
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
ErikaZ
le 22 Août 2018
Réponse apportée : Walter Roberson
le 22 Août 2018
I have a 3D struct with 6 fields.
The struct is a 17x10x16 and each field is a 1x10 array.
I want to calculate the mean of the 10 values in each field. Some of the 3D spaces are empty and needs to fill with NaNs.
So then I can create a separate 17x10x16 array for each field.
Thank you!
0 commentaires
Réponse acceptée
Walter Roberson
le 22 Août 2018
Letting YS be Your Structure,
fn = fieldnames(YS);
for K = 1 : length(fn)
fin = fn{K};
means.(fin) = reshape(mean(vertcat(YS.(fin)),2),size(YS));
end
This will produce a structure means with field names the same as the field names in YS, each of which is an array that is the mean of the field at the corresponding structure entry.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Structures dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!