How to convert a string to a symbol ?
Afficher commentaires plus anciens
Hello guys ,
I just wanted to convert this string :
'x & 1'
to a symbol ,i tried to use sym() function ,which seemed not to work ,obviously ,it doesn't seem to symbolize some characters ,like ampersands ,asterisks ,arithmetic operators , etc...
So any help how can i convert the above string to a symbol ?!
Much Regards
Réponse acceptée
Plus de réponses (3)
Ahmed A. Selman
le 25 Mar 2013
sym and syms are used to declare symbolic variables, see:
Please specify your idea about (converting a string to symbol in Matlab), do you mean (string to a variable), as in
x=1
y=-90
if so, Matlab variables must not contain special characters as (~!@#$%^&*)..etc. Or you mean text properties in figures? Then Refer to http://www.mathworks.com/help/matlab/ref/text_props.html.
If it was translating a string into an expression, see the functions
regexptranslate
regexp
5 commentaires
Jacky
le 25 Mar 2013
Walter Roberson
le 25 Mar 2013
What result are you aiming for, and what are you getting instead?
Jacky
le 25 Mar 2013
Walter Roberson
le 25 Mar 2013
When you use
sym('x & 1')
what result are you seeing?
Question: would x&1 be the formula or the limit? Were you meaning
sym('x < 1')
?
Jacky
le 25 Mar 2013
Walter Roberson
le 25 Mar 2013
1 vote
MuPAD does not use & for logical conjugation. See http://www.mathworks.com/help/symbolic/logical-operations-1.html
Jacky
le 28 Mar 2013
1 vote
Catégories
En savoir plus sur Operations on Strings dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!