How to save the name of a variable and a folder using -printf?

2 views (last 30 days)
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:
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.

Accepted Answer

Rik on 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).
AXL on 14 Mar 2018
You're right. I was thinking wrong! I solve it without eval or assignin!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by