Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



Dynamic Structure
Posted:
Jan 7, 2014 1:46 AM


Good morning(afternoon or night),
I have a question that is more about optimising my MATLAB code. Don?t know if you can help.
% Say I have a predefined list of ratio IDs:
ratioID = [{'AA9';'AA10';'AB112'}];
% To use these IDs as variables in a dynamic structure and assigning a value of 1 to each, I do the following:
for k = 1:3,
struct.(ratioID{k}) = 1;
end
My question is whether it is not possible to assign the values to ID without having to use a forloop? I would think something like struct.(ratioID{1:end}) = 1 should work, but it doesn?t.
My goal is to have a structure called ?struct?, with the fields ?AA9?, ?AA10? and ?AB112?, with each of these fields having a value of 1. In real life, the number of fields is much greater than 3, so
I won?t be able to enter the field names manually.
Thanks in advance



