I am writing an easy IF condition. The function is to judge each row of the matrix to be certain vectors. The code is as follows:
if (compareM(i,:)==[1, 0])||(compareM(i,:) ==[2, 1])
match_1 = match_1 +1;
else
mismatch_1 = mismatch_1 +1;
end
The error said ”Operands to the || and && operators must be convertible to logical scalar values”.
compareM is a n by 2 matrix and I wonder if the error is made by || operation. Thanks in advance!
If you are comparing vectors, not scalar values, you have to use
|operator. As a result you get logical vector of element-by-element pairwise comparison. To use it in IF statement you have to convert either each logical statement (then use||) or the result of|the to scalar with ALL, ANY or other function.If you want to compare to vectors for equality use ISEQUAL function as