How to summon a double variable that it's name was stored in a string?
Afficher commentaires plus anciens
during my program I want to summon a double variable that it's name saved in a string before!How can do it?
Réponse acceptée
Plus de réponses (1)
Daniel Shub
le 19 Oct 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 commentaire
Pouya Jamali
le 19 Oct 2011
Catégories
En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!