MATLAB: How to check if a certain matrix is one of the cells of the cell array

arraycellequalisequalismembermatrix

How can I check if a certain matrix is one of the cells of my cell array? For example, I have
A={[1 2;3 4] [2 2;3 3] [1 1;2 2]};
b=[1 2;3 4];
and I want to check if the matrix b is in one of the cells of A. This should then result in a logical. I have looked up a lot of functions like isequal, ismember and experimented a bit with them, but not one gave me the desired result. Thanks in advance!

Best Answer

Try it with a simple loop:
A = {[1 2;3 4] [2 2;3 3] [1 1;2 2]};
b = [1 2;3 4];
isInCell(A, b)
function R = isInCell(A, b)
R = false;
for k = 1:numel(A)
if isequal(A{k}, b)
R = true;
return;
end
end
ismember and similar functions to not handle cells except for cell strings. See also: https://www.mathworks.com/matlabcentral/answers/352144-unique-on-a-nx1-cell-array-with-different-length-vectors-per-cell
Alternatively:
R = any(cellfun(@(x) isequal(x, b), A))
This is much nicer, but slower: For a {1 x 1e5} cell containing rand(3) matrices, searching for the last element takes 0.13 sec with the loop method and 0.89 sec with cellfun. The earlier the matching matrix appears, the higher is the advantage for the loop.