Why does STRMATCH in MATLAB cause an error for a cell array containing a numeric value?
Show older comments
Why does STRMATCH in MATLAB cause an error for a cell array containing a numeric value?
According to the help for STRMATCH:
I = STRMATCH(STR,STRS) looks through the rows of the character array or cell array of strings
STRS to find strings that begin with string STR, returning the matching row indices.
STRMATCH is fastest when STRS is a character array.
However, as the following example illustrates, STR can be a numeric value, and STRMATCH will not return an error.
str = 9;
strs = strvcat('This is a string array','with two rows');
ind = strmatch(str,strs);
The variable 'ind' will be empty. However, if I try to use STRMATCH with a cell array containing a double, I receive an error as in this next example:
str ={9};
strs = strvcat('This is a cell array of strings','with two rows');
ind = strmatch(str,strs);
??? Error using ==> cell/strmatch
Requires character array or cell array of strings as inputs.
Accepted Answer
More Answers (0)
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!