MATLAB Answers

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

15 views (last 30 days)
Dice-k on 20 Feb 2020
Commented: Dice-k on 20 Feb 2020
Could you please help me to change a valuable name with a minus sign in it?
the valuable name is something like
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.)


Sign in to comment.

Accepted Answer

M on 20 Feb 2020
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".


Dice-k on 20 Feb 2020
Thanks for your comment.
I know what you are talking about... but such valuable actualy exists and I'm having hard time.
The code reading the original sensor data is not mine, thus I do not have much confidence
changing it. It seems the valuable name is defined based on the parameter name shown in
the original file.
Steven Lord
Steven Lord on 20 Feb 2020
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!