strings

Creates a string array filled with empty strings.

Category: Language Fundamentals > Data Types

Syntax

s = strings(n)

Creates an n-by-n array.

s = strings(m, n, ...)

Creates an array with the given dimensions.

s = strings

Returns a single empty string "".

Description

strings is for preallocating text before filling it in a loop, in the same way zeros is used for numbers. The elements are empty strings of length 0, which is different from the missing value <missing>.

A size of 0 gives an empty array, so isempty(strings(0)) is true.

Input arguments

n, m
Non-negative integer sizes.

Output arguments

s
String array whose elements are all "" (zero characters, not missing).

Example

Preallocating text

s = strings(2, 2)
s(1, 2) = "hi"
size(strings(1, 3))
Output
s = 2×2 string array

    ""    ""
    ""    ""
s = 2×2 string array

    ""    "hi"
    ""    ""
ans = 1×2

     1     3

See also

string zeros cell isempty