Convert a character string to an expression
MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
text2expr(text) interprets the character
text as MuPAD® input and generates the
The text must correspond to syntactically correct MuPAD input.
text2expr produces an error. Typically,
strings created from MuPAD objects via
expr2text can be reconverted to corresponding
The object is returned without being further evaluated. Evaluation
can be enforced using the function
text does not need to be terminated with
;" or a "
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
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
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();