Premature optimisation being the root of all evil, instead of trying to do anything fancy, I would simply try and use MATLAB's array notation and vectorisation and then later worry about optimisations. I haven't tested, but there's a decent chance that just vectorising things will be pretty reasonable since it makes the memory accesses required uniform. Here's how I'd do it:
>> M = rand(3,4,7) > 0.5; % Example data
>> A1 = rand(3,4) > 0.5; % (Probably) not a page of M
>> A2 = M(:,:,3); % Page 3 of M
>> find(all(A1==M, [1 2])) % Use implicit expansion to compare
ans =
0x1 empty double column vector
>> find(all(A2==M, [1 2]))
ans =
3
This uses implicit expansion (introduced R2016b) in the Ax == M
piece, and then uses the relatively recent (introduced in R2018b) vectorised dimension specifier to all
for the "reduction" piece.
As per @Wolfie's comment, if you only need to know whether (and not where) a page is present, you can use any
instead of find
if any(all(A2==M, [1 2]))
% Page was present
else
% Page not already present
end