Reputation: 4233
I built a cell array that contains non-string elements, say, vectors containing numbers.
How can I search if a vector exits in this cell array? Since the elements are not strings, I cannot use ismember()
function.
Concretely, if I had a cell array like
a = {[1 2], [2 3], [3 4], [4 5]}
how can I find out if [2 3]
is in this cell array?
Upvotes: 0
Views: 127
Reputation: 3204
You can try this :
ismember(num2str([2 3]), cellfun(@num2str, a, 'UniformOutput', false))
Upvotes: 1
Reputation: 14939
I think this should work:
find(ismember(cell2mat(a'),[2 3],'rows'));
or if you don't need the location:
any(ismember(cell2mat(a'),[2 3],'rows'));
Good luck =)
Upvotes: 2