How to replace 'genvarname' with 'matlab.lang.makeValidName'?
Mostrar comentarios más antiguos
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 comentario
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.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Variables en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!