how to make a variable name from a string
显示 更早的评论
2013a version
>> test='eye'
>> value = [5,5,3]
value =
5 5 3
>> eval([sprintf(test) '= data+1']);
Index exceeds matrix dimensions.
How to fix this error? Thank you for helping!
采纳的回答
更多回答(3 个)
xianghong
2013-8-16
0 个投票
1 个评论
Walter Roberson
2013-8-16
No, it is not just for creating field names within a variable. It shows a number of different alternatives to creating a variable from a string, recommending strongly that you use one of the alternatives instead of creating a variable dynamically. At the end of the FAQ it shows how to create a variable dynamically, for the rare case when you really need to do that. If you are not engaged in creating extensions to MATLAB itself, chances are that there is a better route than creating a variable dynamically.
xianghong
2013-8-16
0 个投票
2 个评论
Walter Roberson
2013-8-16
Please use the command
clear eval
and then try again
xianghong
2013-8-19
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!