How to summon a double variable that it's name was stored in a string?
Mostrar comentarios más antiguos
during my program I want to summon a double variable that it's name saved in a string before!How can do it?
Respuesta aceptada
Más respuestas (1)
Daniel Shub
el 19 de Oct. de 2011
Building on David's answer
xxx = 3;
varname = 'xxx';
val_of_xxx = eval(varname);
can be replaced with
data.xxx = 3;
varname = 'xxx';
val_of_xxx = data.(varname);
The advantage of the latter is it avoids the eval.
1 comentario
Pouya Jamali
el 19 de Oct. de 2011
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!