text2expr

Convert a character string to an expression

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

text2expr(text)

Description

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.

Examples

Example 1

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:

eval(%)

Example 2

A character string is converted to a statement sequence:

text2expr("x:= 3; x + 2 + 1"); eval(%)
(x := 3;
x + 2 + 1)

x

delete x:

Example 3

A matrix is converted to a string:

matrix([[a11, a12], [a21, a22]])

expr2text(%)

The string is reconverted to a matrix:

text2expr(%)

eval(%)

Example 4

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();

Parameters

text

A character string

Return Values

MuPAD object.

See Also

MuPAD Functions

Was this topic helpful?