In this example:
str = 9;
strs = strvcat('This is a string array','with two rows');
ind = strmatch(str,strs);
the normal STRMATCH is used, since the first input is not a cell array. In this case, 9 could be used as an ASCII value, and converted to a tab character. That character can then be compared with the other strings.
In this example:
str ={9};
strs = strvcat('This is a cell array of strings','with two rows');
ind = strmatch(str,strs);
@CELL/STRMATCH will be used, since the first input is a cell array. In this case, the code checks that the cell array contains strings, and converts it to a char array:
if iscellstr(str), str = char(str); end
Cell arrays of strings are special cases of cell arrays, which are commonly used to store strings together which have different lengths, and there are many instances where cell arrays of strings and strings can be used interchangeably. However, {9} is not a cell array of strings, so it is not converted to a character array, which leads to the error being thrown by this code:
if ~ischar(str) | ~ischar(strs)
error('Requires character array or cell array of strings as inputs.')
end
Best Answer