MATLAB: From string to a variable

strings

Hi everybody, i've a string array array={'dog', 'bike', 'donut'} for example from here i need, for each word, a numeric variable with the same name
dog = 5;
bike = 7;
donut = 54;
(doesn't matter the numbers the most importan thing is to create the variable from the string in array )

Best Answer

I would use eval
names = {'dog','bike','donut'}
for i = 1:length(names)
eval([names{i} ' = rand;'])
end