I have the following equation in MATLAB:
eqn1 = (1-t)*x1 + t*x2 == x;
where x1,y1 = <some_constant_value>
I am solving the equation as:
t1 = double(solve(subs(eqn1,x,min(x_arr(i,:))),t));
and doing a comparison as:
if(t1 >= 0 & t1 <= 1)
crossing = 1;
return
end
However, from time to time, I get the following error:
Operands to the || and && operators must be convertible to logical scalar values.
From what I found out on other forums/answers, this is because &&
and ||
is not capable of handling arrays and hence, the error. But, considering I am solving a linear equation, why is MATLAB returning an array?
EDIT
My apologies, I forgot to give the initialization for the variables:
syms x y t
x1
as double
x2
as double
y1
as double
y2
as double
x_arr
as double
y_arr
as double