string.string
string: str = string ()
string: str = string (in)
string: str = string (calendarDuration, 'Format', FMT)
string: str = string (duration, 'Format', FMT)
string: str = string ({in1, …, inN})
Create a new string array.
str = string () creates a scalar string array, whose element
contains an empty character vector.
str = string (in) creates a string array of the same
size as in, which is converted to string according to the following
options:
num2str function.
false or
true character sequences.
cellstr method.
dispstrings method.
cellstr methods, in which case an extra pair argument
is supported to allow parsing to the respective method the appropriate
display format. See calendarDuration and duration for
valid formats parsed through FMT to each class method. Extra input
arguments to the string constructor except for this case are
ignored.
str = string ({in1, …, inN}) creates a
string array from a cell array, which may contain any combination of the
aforementioned data types, provided that each cell element is compatible
to a string scalar. When using this syntax, calendarDuration arrays and
duration arrays are converted via their dispstrings method, hence
no extra format argument is meaningful.
See also: calendarDuration, categorical, datetime, duration, missing
Source Code: string
A string is MATLAB's string-array type. There is a crucial Octave difference to keep in mind: in core Octave BOTH 'text' and "text" produce ordinary character vectors (class char) — unlike MATLAB, the double quote does not make a string. Only the string constructor produces a string array.
class ('text') % single quotes -> char
ans = char
class ("text") % double quotes -> ALSO char in Octave
ans = char
class (string ('text')) % the constructor -> string
ans = string
Build a string array from a cell array of character vectors — one element per cell. A string array prints its elements in double quotes.
string ({'apple'; 'banana'; 'cherry'})
ans =
3x1 string array
"apple"
"banana"
"cherry"
Numbers convert to their text form.
string ([3.14, 42, -1])
ans =
1x3 string array
"3.14" "42" "-1"
The special <missing> value is the string counterpart of NaN, and is distinct from an empty string "". Assign string (missing) to introduce one.
s = string ({'a'; 'b'; 'c'})
s =
3x1 string array
"a"
"b"
"c"
s(2) = string (missing)
s =
3x1 string array
"a"
<missing>
"c"
ismissing (s)
ans = 0 1 0