If I\'m using a char string as the needle and a cell array of chars as the haysack, would the following achieve the same results every time? I\'m looking at their d
No, the results will be different. The function strmatch returns a vector of indexes where the cell array (haystack) matches the string (needle):
>> arr = {'a', 'b', 'c', 'a', 'b'};
>> strmatch('a', arr, 'exact')
ans =
1
4
The strcmp function returns a logical vector, with 1s where the haystack matches and 0s where it doesn't match:
>> strcmp('a', arr)
ans =
1 0 0 1 0
On the other hand, the expression find(strcmp('a', arr)) is equivalent to strmatch('a', arr, 'exact').
strmatch is not recommended. Use strncmp or validatestring instead. strmatch will be removed from a future version of matlab.
*Warning given in Matlab 2017 a.