MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

L = 11


L = strlength(str)


L = 11


You also can use strlength on string arrays containing multiple strings and on cell
arrays of character vectors.


The length function returns the size of the longest dimension of an array. For a string
array, length returns the number of strings along the longest dimension of the array. It
does not return the number of characters within strings.


Why Does isempty("") Return 0?


A string can have no characters at all. Such a string is an empty string. You can specify an
empty string using an empty pair of double quotes.


L = strlength("")


L = 0


However, an empty string is not an empty array. An empty string is a string scalar that
happens to have no characters.


sz = size("")


sz = 1×2
1 1


If you call isempty on an empty string, then it returns 0 (false) because the string is
not an empty array.


tf = isempty("")


tf = logical
0


However, if you call isempty on an empty character array, then it returns 1 (true). A
character array specified as a empty pair of single quotes, '', is a 0-by-0 character array.


tf = isempty('')


tf = logical
1


Frequently Asked Questions About String Arrays
Free download pdf