I have a struct res with the variables: det1, det2, det3.
I also have the amount of these variables (in this case 3), and I want to read them in a loop.
How can I integrate the iteration variable in the name of the variables in the loop and read them?
I want to do something like this:
for i=1:num_variables
var_name = 'res.det'+num2str(i);
% read var_name
end
Thanks for the help!
your_fields = fields(your_struct), you can then loop over that array, e.g.res.your_fields(ii). What do you mean by "reading" them? If you have a structure, the data stored within is already loaded into MATLAB, i.e. usable. All you need to do is refer to it.