Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

How generate nested structs and access to them?

1 Ansicht (letzte 30 Tage)
Chewy
Chewy am 7 Nov. 2015
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
I wrote a test-script to generate a struct with several sub-structs. The variable 'template_matching_results' shall be a list of all 'i_i', which is flag for different images. The sub-structs 'i_i' shall contain a list of all 'i_t'. In this way I want to create further level of the struct 'w_i_t' and 'v_trans_i_t'. The last one shall be a long table with the colomns 'h_trans_i_t', 'sum_ones_i_i', 'sum_ones_i_t', 'sum_matches'.
How can I get the following script filling the struct with the indexes of the loops?
clear all;
template_matching_results = struct('i_i', '');
template_matching_results.i_i = struct('i_t', '');
template_matching_results.i_i.i_t = struct('w_i_t', '');
template_matching_results.i_i.i_t.w_i_t = struct('v_trans_i_t', '');
template_matching_results.i_i.i_t.w_i_t.v_trans_i_t = struct('h_trans_i_t', '', 'sum_ones_i_i', '', 'sum_ones_i_t', '', 'sum_matches', '');
for i_i = 1:3
template_matching_results.i_i = i_i;
for i_t = 1:3
template_matching_results.i_i.i_t = i_t;
for w_i_t = 1:3
template_matching_results.i_i.i_t.w_i_t = w_i_t;
for v_trans_i_t = 1:3
template_matching_results.i_i.i_t.w_i_t.v_trans_i_t = v_trans_i_t;
end
end
end
end

Antworten (0)

Diese Frage ist geschlossen.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by