MATLAB: How can one dynamically assign names for tables

cell arraydynamicdynamic variable namesevaltable

Hi!
I would like to dynamically assign names for tables, but I get an error – 'Index exceeds matrix dimensions.' Real example is somewhat more complex, but the core idea is here, in a minimal example:
T = table(['M';'F';'M'],[45;32;34],...
{'NY';'CA';'MA'},logical([1;0;0]),...
'VariableNames',{'Gender' 'Age' 'State' 'Vote'});
for i=1:3
s = ['A_',num2str(i),'= T'];
eval(s);
end
Does anyone have an idea where this error comes from and how to overcome it?
Thanks!

Best Answer

Bad idea. See the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F How would you even refer to them once you made them? You can hard code them in if you want
A_1 = T;
A_2 = T;
A_3 = T;
because then afterwards in the code you'll know the names of the variables. Or else you could put the table into multiple cells in a cell array but that just seems like an unnecessary complication so I don't even want to tell you how to do it (unless you give a really compelling reason why you need that).