# Why does this test yield True

I have this test implemented in my code, when I import a numeric matrix, which I thought would be bulletproof, but it's failing in this case:

In[]:= MatrixQ[{{}, {}}, NumericQ[#] && MatchQ[#, _Real] &]

Out[]= True


I don't get it.

Because there are no elements in your matrix. So there is no element which is not numeric and real.

MatrixQ[{{}, {}}, False &]


returns True too.

So you have to exclude that case:

MatrixQ[##, NumericQ[#] && MatchQ[#, _Real] &] && !MatrixQ[##, False &] &

• I'd find the example MatrixQ[{{}, {}}, False &] somewhat more convincing. (Typo? If not, consider MatrixQ[{{1}, {1}}, True].) Or maybe MatrixQ[{{}, {}}, Print] vs. MatrixQ[{{1}, {1}}, Print]. In any case, +1. – Michael E2 Oct 15 '16 at 21:40
• @MichaelE2 Whoops. Thanks for pointing out – meneken17 Oct 15 '16 at 21:43
• Thanks! And how can I catch this case? I have tried several things without success. – Santiago Oct 16 '16 at 9:18