It really took me quite a while to figure this out. Just take notes for myself.
Syntax 1 Create an array of struct
tree(1,10) = struct(‘a’, );
Syntax 2 Create an array of struct, each field of which is assigned a struct of itself
[tree(1:10).b] = deal(tree);
The function: k is the number of brunches, L is the number of levels. inverted_file is the matrix data need to be assigned to each node in the tree structure.
function tree = create_tree(k, L) %leaves subtree(1,k) = struct('inverted_file', ); %grow to the roots for i = 1:L-1 [subtree(1:k).subtree]=deal(subtree); end %wrap it in a tree structure tree = struct('depth', L, 'branch', k, 'subtree', subtree); end