matching with data in cell array
56 views (last 30 days)
Show older comments
i want to match the output with data in cell array, i want to check whether the number(output) lies in cellarray or not?
Answers (2)
ES
on 1 Jun 2017
[truefalse, index] = ismember('abc', {'xyz', 'abc', 'def', 'abc'})
This one?
12 Comments
Walter Roberson
on 10 Jul 2017
The suggested
nnz(ismember('EK94P8',ANPR(:,2)))
should be
nnz(ismember(ANPR(:,2), 'EK94P8'))
When you use ismember(A, B) then for each entry in A, a logical value (true or false) will be returned indicating whether that entry in A was found in B. So if you reverse the order like I show, then for each entry in your second column of ANPR, you are comparing it to the one value 'EK94P8', returning a logical value for each. The number of matches is the same as the number of places the logical value is true, which is the same as the number of places the logical value is non-zero. The number of places that a value is non-zero can be tested with nnz()
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!