How to save the name of a variable and a folder using -printf?
1 次查看(过去 30 天)
显示 更早的评论
I want a certain folder to be created according to the number of elements given by the user.
dir_Cantilever_EPD_3000Elem = [pwd ...
'\Results\Cantilever Beam Domain\3000 Elements\EPD']
I want the variable named and the name of the folder to be like that:
sprintf('dir_Cantilever_EPD_%dElem',fem.NElem)
where fem.NElem is the number of elements given. So I do not have to do lots of 'if' to check the number os elements.
0 个评论
采纳的回答
Rik
2018-3-13
You can do this with eval, but you shouldn't. Use a cell array instead.
(I have taken the liberty of adapting some of Stephen Cobeldick's thoughts on this topic) Introspective programing (eval and other functions like it) is slow, and the MATLAB documentation warns specifically against it. Using eval is slow, makes debugging difficult, and removes all code helper tools (code checking, syntax hints, code completion, variable highlighting, etc.). A longer discussion can be found here. If you are not an expert and you think you need eval, there are probably better solutions to your problem. Also, if you are not an expert, you might find interesting and helpful hints on this page (and if you are an expert, you can still learn from it).
3 个评论
Rik
2018-3-13
assignin and eval are usually solutions to problems arising from a bad data structure. If you explain what you're trying to accomplish I (or any other contributor) might be able to help with what you should do, instead of only being able to say what you shouldn't do.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Install Products 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!