How to replace 'genvarname' with 'matlab.lang.makeValidName'?
Ältere Kommentare anzeigen
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 Kommentar
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.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Variables finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!