Is it possible to translate a string with operators into an actual equation?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Is it possible to translate a string with operators into an actual equation?

bobkarh
Let´s say I have the string a= "2+2" . So that class(a) = char. Is there a way to transform the string "2+2" into the actual equation a=2+2 so that the answer is a = 4???
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to translate a string with operators into an actual equation?

Markus Bergholz


On Tue, Sep 16, 2014 at 7:42 PM, bobkarh <[hidden email]> wrote:
Let´s say I have the string a= "2+2" . So that class(a) = char. Is there a
way to transform the string "2+2" into the actual equation a=2+2 so that the
answer is a = 4???

octave:1> a="2+2"
a = 2+2
octave:2> a=eval(a)
a =                    4

 



--
View this message in context: http://octave.1599824.n4.nabble.com/Is-it-possible-to-translate-a-string-with-operators-into-an-actual-equation-tp4666541.html
Sent from the Octave - General mailing list archive at Nabble.com.

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave



--
icq: 167498924
XMPP|Jabber: [hidden email]

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to translate a string with operators into an actual equation?

bobkarh
In reply to this post by bobkarh
Ooops nevermind, found it myself .. the function eval("string") , evaluates a string as if it was an Octave function. So eval("2+2") = 4