Is the 3rd test case good? I think something is wrong there!
All the other cases pass but the 3rd fails with this error:
"Index exceeds matrix dimensions. Error in Test3>@(a)isequal(M(:,:,a),eye(2)) Error in Test3 (line 7) a1=arrayfun(@(a) isequal(M(:,:,a),eye(2)),ids);"
I checked the result manually and it should be fine (provided that I understood the task right)