Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

How generate nested structs and access to them?

3 visualizzazioni (ultimi 30 giorni)
Chewy
Chewy il 7 Nov 2015
Chiuso: MATLAB Answer Bot il 20 Ago 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

Risposte (0)

Questa domanda è chiusa.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by