MATLAB: I’m trying to compare components of an array using relational operators, and the outcome needs to be either true or false. My result is a row vector of logicals; how do i make sure the result is just a single 1 or 0

value true

A=rand(15,10); B=any(A(8,:))==max(A); B= 0 0 0 0 0 0 0 0 0 0

Best Answer

Note that like many MALTAB functions, max , any and all work along one (default or specified) dimension. If you wish for these function to operate on every element in the array, then you can use the syntax (:), regardless of the size of the array, eg:
any(X(:))
So one solution for your code would be:
A = rand(15,10);
B = any(A(:)==max(A(:)));
Unless you need that (8,:) indexing for some other purpose...