strings - Create string array with no characters - MATLAB (original) (raw)
Create string array with no characters
Syntax
Description
str = strings
returns a string with no characters. For more information on string arrays, see string.
You also can use double quotes. For example, str = ""
creates a string scalar that contains no characters.
str = strings([n](#bu5f7ms-n))
returns ann
-by-n
string array. Each element is a string with no characters.
str = strings([sz1,...,szN](#bu5f7ms-sz1szN))
returns asz1
-by-...-by-szN
string array, wheresz1,...,szN
indicate the size of each dimension. For example,strings(2,3)
returns a 2-by-3 string array where each element is ""
.
str = strings([sz](#bu5f7ms-sz))
returns a string array where size vector sz
defines size(str)
. For example,strings([2,3])
returns a 2-by-3 string array.
Examples
Square Array of Empty Strings
str = 4x4 string "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
Rectangular Array of Empty Strings
str = 2x6 string "" "" "" "" "" "" "" "" "" "" "" ""
Clone String Array Size from Existing Array
Create an array of empty strings that is the same size as an existing array.
A = [1 2 3; 4 5 6]; sz = size(A); str = strings(sz)
str = 2x3 string "" "" "" "" "" ""
It is a common pattern to combine the previous two lines of code into a single line:
You can use strings
to preallocate the space required for a large string array.
Input Arguments
n
— Size of square array
nonnegative integer
Size of a square array, specified as a nonnegative integer.
- If
n
is0
, thenstr
is an empty array. - If
n
is negative, thenstrings
treatsn
as0
.
Data Types: double
| single
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
sz1,...,szN
— Size of each dimension (as separate arguments)
nonnegative integers
Size of each dimension, specified as separate nonnegative integer arguments.
- If the size of any dimension is
0
, thenstr
is an empty array. - If the size of any dimension is negative, then
strings
treats it as0
. - Beyond the second dimension,
strings
ignores trailing dimensions with a size of1
. For example,strings(3,1,1,1)
produces a 3-by-1 vector of strings with no characters.
Data Types: double
| single
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
sz
— Size of each dimension (as a row vector)
nonnegative integers
Size of each dimension, specified as a row vector of nonnegative integers. Each element of this vector indicates the size of the corresponding dimension:
- If the size of any dimension is
0
, thenstr
is an empty array. - If the size of any dimension is negative, then
strings
treats it as0
. - Beyond the second dimension,
strings
ignores trailing dimensions with a size of1
. For example,strings([3,1,1,1])
produces a 3-by-1 vector of strings with no characters.
Example: sz = [2,3,4]
creates a 2-by-3-by-4 array.
Data Types: double
| single
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Extended Capabilities
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Version History
Introduced in R2016b