Creating a string with sprintf() and assign a variable to it
19 次查看(过去 30 天)
显示 更早的评论
Hello
I have a basic question which I can not solve. I am creating multiple variables with sprintf and I would be interested to assign an array to each of them.
I tried to do it in some ways but did not work. Is there any way to do it ?
Thank you in advance
0 个评论
采纳的回答
Honglei Chen
2012-8-13
编辑:Honglei Chen
2012-8-13
Don't know what you are trying to do but here is an example.
eval(sprintf('A%d = %s',1,'magic(3)'))
As a general rule though, you should avoid using variables such as A1, A2, (you may not have this issue, I just put it as a precaution), see
2 个评论
Walter Roberson
2012-8-13
Using eval() very often leads to problems in coding and debugging. It is much better to use one of the alternatives such as cell arrays.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!