special character in symbolic variable name
33 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have discovered a nice way to name symbolic variables and would like to extend it a bit, but can't find the correct documentation. First, I created a MuPAD notebook, and used the statement
xi0:=Symbol::subScript(Symbol::xi,0):
Then, I converted the notebook to a Live Script, and saw the following code
syms xi_0
xi0=xi_0;
With that, I can create expressions using xi0 and they are displayed very nicely in the Live Script output. If possible, I would like to extend this and create a variable for the absolute value of 'q', and tried the following (based on the Unicode character for a double vertical line):
doubleVerticalLine=char(8214)
qabs=strcat(doubleVerticalLine,'q',doubleVerticalLine)
eval(['syms ',qabs]);
Here are my problems:
- I can't find the documentation for syms xi_0. This is not Tex, and there is no "\" in front of the xi, so I don't know how to extend it. I do know that the underline means subscript in MATLAB.
- I haven't found a way to make this work using eval, not even for the simple case of xi.
- It looks like the double vertical line is not allowed in variable names, so I would need to find something else, but where is the documentation for it? Maybe I could somehow convert on output, not in the expression itself.
I would be happy to share my script individually, but I don't want to broadcast this very unfinished piece of work to a large audience.
0 Kommentare
Antworten (1)
Steven Lord
am 6 Okt. 2016
You are correct that the double vertical line is not an allowed character in a variable name in MATLAB, as it doesn't satisfy the requirements given in the documentation for the isvarname function.
In general creating dynamic variable names is strongly discouraged, though your case is slightly different than the usual.
2 Kommentare
Walter Roberson
am 6 Okt. 2016
In MATLAB, variable numbers must begin with a "letter", after which they can have "letter" or the digits 0 to 9, or underscore. The permitted letters are A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z .
To put it another way, the letters must satisfy
TheCharacter <= 127 & isstroprop(TheCharacter, 'alpha')
where TheCharacter is the 16 bit Unicode encoding of the character (characters beyond U+FFFF are not supported in MATLAB.).
The first 127 Unicode positions are the first 127 ISO-8996-1 positions, which are in turn the first 127 US-ASCII positions.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!