# MATLAB: Getting variables name from char array

MATLABvariablevariables

assuming I have a char array like x
``a1=[1 2 3 4];a2=[10 11 15 11];b2=[4 5 6 7];c2=[8 9 10 11];x=['a1' 'a2' 'b2' 'c2']``
assuming I have data like this, how can I make the char in x be treated like the variable name meaning that ('a1' –> a1 == [1 2 3 4])
Notes: – All the variables are created before the char array
– I have to name the variables like (a1,a2,..etc.)
-I have a large number of variables

``myStruct.a1=[1 2 3 4];myStruct.a2=[10 11 15 11];myStruct.b2=[4 5 6 7];myStruct.c2=[8 9 10 11];x={'a1' 'a2' 'b2' 'c2'}; % you need a cell array here. The code line in your question will not work``
``>> myStruct.(x{1}) % same as myStruct.a1ans =     1     2     3     4>> myStruct.(x{3})ans =     4     5     6     7``
``a1=[1 2 3 4];a2=[10 11 15 11];b2=[4 5 6 7];c2=[8 9 10 11];x={'a1' 'a2' 'b2' 'c2'}; % you need a cell array here. The code line in your question will not work``
``>> eval(x{1})a1 =     1     2     3     4>> eval(x{4})c2 =     8     9    10    11``