eval - Create variables from an array of cells in Matlab -
i have array of cells, example,
cells = {'a', 'b', 'c', d', 'e'};
which inside loop of 1 5.
i want create variable e depending on loop index, 1 a, 2 b...
when try (i
index),
eval(cells{i}) = values;
gives me error,
undefined function or method 'eval' input arguments of type 'a'
here answer:
eval(sprintf([cells{i} '=values;']))
and can remove ;
if want see display in command window.
in answer comment :
cells = {'a', 'b', 'c', 'd', 'e'}; values = 4; = 1; eval(sprintf([cells{i} '=values;']))
this works fine on computer, , no warning or error messages.
Comments
Post a Comment