Your code is a little confusing because it doesn't appear that you are assigning anything to the structure. Here is code that does assign values to the structure:
names = {'danny';'edgar';'larry'};
field = {'one';'two';'three'};
for ii =1:length(names)
Newstruct.(names{ii}).(field{ii}) = ii;
end
This is how I am interpreting your code. It could be that you mean this instead (or switch names and field...):
names = {'danny';'edgar';'larry'};
field = {'one';'two';'three'};
for ii =1:length(names)
Newstruct.(names{ii}) = field{ii};
end
If these aren't what you mean, please create one top level of the new structure by hand and show the code. Then perhaps we can figure out how to make it from names and values.
Best Answer