MATLAB: ERROR Operands to the || and && operators must be convertible to logical scalar values

operands

please give me example why i got error "Operands to the and && operators must be convertible to logical scalar values."
value = zeros(2374,1);
if (predChar >= 0.3) && (dylo >= 0.2) && (dyhi >= 0.2)
value(value)=1
else
value( value)=0;
end
i have 3 matrix, predchar, dylo and dyhi which i want to replace with 1 or 0

Best Answer

The inputs to && and || must be scalars. This means that this is an error:
[12,3,4]>2 && [true,false,true]
But that this is not an error (both inputs are scalar):
12>2 && true
But you probably should be using indexing, not an if statement:
value = zeros(2374,1);
idx = predChar>=0.3 & dylo>=0.2 & dyhi>=0.2;
value(idx) = 1;