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

3 Ansichten (letzte 30 Tage)
Alexander Vincent
Alexander Vincent am 11 Aug. 2015
Beantwortet: David Young am 11 Aug. 2015
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

Antworten (1)

David Young
David Young am 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.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by