strlength
Number of characters in each string.
Category: Language Fundamentals > Data Types
Syntax
L = strlength(str)
Returns the length of each text in str.
Description
strlength counts characters per element of a string array, so strlength(["hello" "" "ab"]) is [5 0 2]. This differs from length and numel, which would report the number of strings in the array rather than the size of each string.
For a missing string the result is NaN.
Input arguments
str- String array, character vector, or cell array of character vectors.
Output arguments
L- Double array of the same size as
str; for a character vector, a scalar.
Example
Per-string lengths
strlength(["hello" "" "ab"])
strlength('abc')
length(["hello" "" "ab"])
Output
ans = 1×3
5 0 2
ans = 3
ans = 3