What's the most efficient way of checking if all rows of a matrix are numerically equal? Preferably looking for something without a for loop.
Find difference between consecutive elements across columns
with diff(..,1)
and then detect if all such differences are zeros with nnz(..)==0
, giving us a easy-peasy-chessy one-liner and pretty efficient solution -
isallrowsequal = nnz(diff(A,1))==0 %// A is input matrix
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With