There must be a simple matlab way of doing this. I have a row vector and I want to check if all of the elements are equal. Brute forcing this in a loop is easy, but looking for a more efficient approach :) The elements are integers
To check if all values in an array are equal:Use the Array. every() method to iterate over the array. Check if each array element is equal to the first one. The every method only returns true if the condition is met for all array elements.
tf = isequal( A,B ) returns logical 1 ( true ) if A and B are equivalent; otherwise, it returns logical 0 ( false ).
I think it can be as simple as
if all(v == v(1))
Another method would be
if range(v) == 0
Another solution:
numel(unique(v))==1
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