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

조회 수: 4 (최근 30일)
Alexander Vincent
Alexander Vincent 2015년 8월 11일
답변: David Young 2015년 8월 11일
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

답변 (1개)

David Young
David Young 2015년 8월 11일
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.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by