MATLAB: How to check to see if the elements in a matrix are all equal

checkequal elementsmatric

So if I have matrix A=[1 1 1 ; 1 1 1 ; 1 1 1] I would like to run a check so check if all the elements in the matrix are the same. Or say matrix B = [1, 0 1; 0 1 0; 1 1 0] I would liek to run a check to see if the elements are all the same ( in this case they aren't).

Best Answer

a = num2cell(A);
isequal(a{:})