How to save the name of a variable and a folder using -printf?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Rik
il 13 Mar 2018
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 Commenti
Rik
il 13 Mar 2018
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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Install Products in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!