Create a variable-name of of a string/char

조회 수: 7 (최근 30일)
Ali Sahouli
Ali Sahouli 2020년 2월 10일
편집: KSSV 2020년 2월 10일
Hello all,
there is a variable called "exaple" and in her there are 1x28 chars ('Hallo_World_I_need_your_help').
I need that char as a variable-name. How can I create a variable name out of the string/char 1x29 which is saved into that "example" variable.
Right now its like that:
exaple =
'Hallo_World_I_need_your_help'
What I need is:
Hallo_World_I_need_your_help =
'example'
Thank you for any help!
  댓글 수: 1
Adam
Adam 2020년 2월 10일
'I need that char as a variable-name'
Why? A variable name is just an internal handle in code, it shouldn't ever need to be anything specific. You can dynamically create fieldnames on a structure, which you can also easily access afterwards, also via the string, but dynamically naming variables is never a good idea:

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

답변 (2개)

KSSV
KSSV 2020년 2월 10일
편집: KSSV 2020년 2월 10일
You may try something like this:
myvariable = 'Hello_World_I_need_your_help' ;
assign( myChar, rand(10) )
Refer here fir the function assign.

Walter Roberson
Walter Roberson 2020년 2월 10일

카테고리

Help CenterFile Exchange에서 Variables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by