Saving structures from each iteration into a structure? Good idea? How?

4 views (last 30 days)
The code below goes through a list of filenames and for each one run all three functions. Each function returns a structure of variables. I'm looking to store each version of the structures from each filename iteration in a structure. Is this suitable and/or possible? Previous tries have not worked well.
for a = 1:length(s_filename_list);
data_filename = s_filename_list{1,a};
prefs = sensor_preferencesG(pref_filename);
[outputA,glider_eng] = sensor_processingAG(data_filename,prefs,eng_filename,a);
outputB = sensor_processingBG(prefs,outputA);
end

Answers (1)

David Young
David Young on 11 Aug 2015
Not sure what you've tried already and had problems with, but I'd have thought it was as simple as putting the results into structure arrays. So to keep all the "output" structs you'd just do:
for a = 1:length(s_filename_list);
data_filename = s_filename_list{1,a};
prefs = sensor_preferencesG(pref_filename);
[outputA(a),glider_eng] = sensor_processingAG(data_filename,prefs,eng_filename,a);
outputB(a) = sensor_processingBG(prefs,outputA(a));
end
It's possible to preallocate the structure arrays to shave a little off the time, but it's probably not worth worrying about doing that.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!