How to convert a string to a symbol ?
Show older comments
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
Accepted Answer
More Answers (3)
Ahmed A. Selman
on 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 Comments
Jacky
on 25 Mar 2013
Walter Roberson
on 25 Mar 2013
What result are you aiming for, and what are you getting instead?
Jacky
on 25 Mar 2013
Walter Roberson
on 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
on 25 Mar 2013
Walter Roberson
on 25 Mar 2013
1 vote
MuPAD does not use & for logical conjugation. See http://www.mathworks.com/help/symbolic/logical-operations-1.html
Jacky
on 28 Mar 2013
1 vote
Categories
Find more on Operations on Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!