How to replace 'genvarname' with 'matlab.lang.makeValidName'?
古いコメントを表示
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 件のコメント
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.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Variables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!