if (str == "")
disp 'str has zero characters'
end
str has zero characters
Do not use the isempty function to test for empty strings. A string with zero characters
still has a size of 1-by-1. However, you can test if a string array has at least one dimension
with a size of zero using the isempty function.
Create an empty string array using the strings function. To be an empty array, at least
one dimension must have a size of zero.
str = strings(0,3)
str =
0x3 empty string array
Test str using the isempty function.
isempty(str)
ans = logical
1
Test a string array for empty strings. The == operator returns a logical array that is the
same size as the string array.
str = ["Mercury","","Apollo"]
str = 1x3 string array
"Mercury" "" "Apollo"
str == ''
ans = 1x3 logical array
0 1 0
6 Characters and Strings