Convert a character string to an expression
This functionality does not run in MATLAB.
text2expr(text) interprets the character string text as MuPAD® input and generates the corresponding object.
The text must correspond to syntactically correct MuPAD input. Otherwise, text2expr produces an error. Typically, strings created from MuPAD objects via expr2text can be reconverted to corresponding objects.
The object is returned without being further evaluated. Evaluation can be enforced using the function eval.
The text does not need to be terminated with a ";" or a ":" character, respectively.
text cannot refer to local variables of an enclosing procedure by their name. The text is parsed as if entered interactively. Cf. Example 4.
A character string is converted to a simple expression. The newly created expression is not evaluated automatically:
text2expr("21 + 21")
It may be evaluated via eval:
A character string is converted to a statement sequence:
text2expr("x:= 3; x + 2 + 1"); eval(%)
(x := 3; x + 2 + 1)
A matrix is converted to a string:
matrix([[a11, a12], [a21, a22]])
The string is reconverted to a matrix:
text2expr will not create a DOM_VAR of an enclosing procedure from its name:
a := "global identifier": g := proc() local a; begin a := "local variable"; print(a); print(eval(text2expr("a"))); end_proc: g();