How to summon a double variable that it's name was stored in a string?
显示 更早的评论
during my program I want to summon a double variable that it's name saved in a string before!How can do it?
采纳的回答
更多回答(1 个)
Daniel Shub
2011-10-19
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Numeric Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!