How to replace 'genvarname' with 'matlab.lang.makeValidName'?
14 views (last 30 days)
Show older comments
Hi,
I'm using 'genvarname' to create variables names from strings. Example:
temp = 'abc'
v = genvarname(temp)
eval([v,'=5'])
Result
abc = 5
In Matlab 2017a I've got a suggestion to replace 'genvarname' with 'matlab.lang.makeValidName' as 'getvarname' will be removed from future releases. Could anyone help me with rewriting my example using 'matlab.lang.makeValidName'?
1 Comment
Stephen23
on 21 Mar 2017
Edited: Stephen23
on 21 Mar 2017
Creating or accessing variables names dynamically will make code buggy and slow, as a thousand discussions and threads on this forum have explained:
The documentation advises avoiding this as well:
The MATLAB blogs too:
If you want to learn to use use MATLAB efficiently then simply use indexing, and avoid bad practices like eval.
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!