How to replace 'genvarname' with 'matlab.la​ng.makeVal​idName'?

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'?

 채택된 답변

ES
ES 2017년 3월 21일
temp = 'abc'
v = matlab.lang.makeValidName(temp)
eval([v,'=5'])

댓글 수: 1

Well, thanks a lot, but I'm a bit ashamed... I've tried that before but didn't work - seems I've made some mistakes. Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Variables에 대해 자세히 알아보기

질문:

2017년 3월 21일

편집:

2017년 3월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by