Info

此问题已关闭。 请重新打开它进行编辑或回答。

How generate nested structs and access to them?

2 次查看(过去 30 天)
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

回答(0 个)

此问题已关闭。

产品

Community Treasure Hunt

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

Start Hunting!

Translated by