Determine average of results from a loop.

1 vue (au cours des 30 derniers jours)
ajk1
ajk1 le 25 Mai 2016
Commenté : ajk1 le 25 Mai 2016
Hi, I have a loop that outputs a 297x258x104 dataset that I have called 'info2'. I have stored these in 'info.table' using the below line ('it' has been previous defined in the loop as: it=1:5).
info.(['table' num2str(it)]) = info2;
Therefore I can now access each of the 297x258x104 from each iteration using 'info.table1', 'info.table2', etc...
I would now like to average all the results of info.table ((info.table1 + info.table2 + info.table3 + info.table4 + info.table 5)/5) to output one 297x258x104 dataset. Thanks.

Réponse acceptée

Jos (10584)
Jos (10584) le 25 Mai 2016
This task becomes trivial when you use an array of structs rather than variable field names.
for it = 1:5
info2 = rand(2,3,2) % some calculation here
info(it).table = info2 ; % create array of structs
end
Big4DResultTable = cat(4,info(:).table)
MeanResultTable = mean(Big4DResultTable,4)
Pro-Tip: It is the contents of a variable (or field) that should change, not the name of the variable (or field).
  1 commentaire
ajk1
ajk1 le 25 Mai 2016
Thank you Jos, that worked perfectly and thanks also for the tip.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by