Texts (character strings)
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.
Texts (which are not really “mathematical objects”,
but useful to the programmer) in MuPAD® are of domain type
MuPAD can manipulate texts (strings of characters). These are primarily used for output and data input.
As far as
concerned, a string cannot be dissected:
s := "this is a string": op(s, 1), op(s, 2)
To access individual characters or substrings, use indexed access:
Assigning to a substring may change the length of a string:
s[6..7] := "changes"; s
Using a string as a function returns the string unchanged. The arguments are not evaluated.
Strings can be concatenated using the dot operator or its functional
The length of a string can be obtained using
Substrings and individual characters (which are strings of length
1) can be accessed using
indexed access, with indices starting at 1 and
negative indices counting from the end of the string:
It is also possible to perform an indexed assignment to a string,
cf. Example 1.
To convert a string into the MuPAD expression that would
be obtained by using the string as an input, use
text2expr. For simple MuPAD expressions,
it is possible to get a string that evaluates to that expression using
that are not convertible in this way include all expressions containing local variables set with
escape. Also, expressions involving floating
point numbers usually will change when being converted to strings
Strings are atomic, i.e., they have exactly one operand, the string itself.
The output form of strings is very similar to their input form. When typesetting, spaces at the beginning and the end of strings are ignored and multiple adjacent blanks as well as newlines are collapsed to a single space.
A string is created by enclosing characters in a pair of typewriter
"this is a string". The following special
sequences are supported (but see below for the typeset output; these
are useful only for non-typeset output):
"\n" denotes an end-of-line character.
"\b" is almost identical to
except that for “pretty-printing” it encodes the baseline
of the current object.
"\t" is a tabulator.
"\\" encodes a backslash.
See the documentation of