How can I work on a valuable name with a minus sign in it...?

조회 수: 14 (최근 30일)
Dice-k
Dice-k 2020년 2월 20일
댓글: Dice-k 2020년 2월 20일
Hello,
Could you please help me to change a valuable name with a minus sign in it?
the valuable name is something like
"data.a-b"
Thus, when I try to call the valuable in the command prompt,
matlab recognizes as the following
data.a - b (i.e., data.a minus b, instead of a single valuable.)

채택된 답변

M
M 2020년 2월 20일
From this documentation:
"valid variable name starts with a letter, followed by letters, digits, or underscores"
You cannot include the " - " symbol in a matlab variable name.
If you want to define a variable that corresponds to " a - b", you can call it "a_minus_b".
  댓글 수: 3
Steven Lord
Steven Lord 2020년 2월 20일
As of release R2019b table and timetable arrays can contain variables with names that are not valid MATLAB identifiers, but you need to use a slightly different syntax to access those variables. See that Release Note entry for more information.
You cannot have plain MATLAB variables whose names are not valid MATLAB identifiers.
Dice-k
Dice-k 2020년 2월 20일
Thanks Steven,
a_b = data.('a-b');
worked!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by