MATLAB: Problem with execution of “nested if” commands.

conditional ifnested ifpiecewise

I need to find values of a piece wise linear function. I used nested if condition as shown in code. But for all values of t, it is executing only first "if else" loop, and giving always x1d(t)= 0.5 andx2d(t)= 0.5 as output values. Am not able to figure out the mistake. help me.
for t = 1:1:26
if 0<t<=4
x1d(t) = 0.5*t;
x2d(t) = 0.5*t;
elseif 4<t<=7
x1d(t) = 0.5*t;
x2d(t) = 3.33;
elseif 7<t<=10
x1d(t) = 0.5*t;
x2d(t) = 10/3 - 0.5*(t-40/3);
elseif 10<t<=26
x1d(t) = 0.5*t;
x2d(t) = 0;
end
end

Best Answer

This if 0<t<=4 doesn't work properly in MATLAB, but this does if 0<t && t<=4 , you have to separate the conditions because MATLAB doesn't evaluate two conditions at the same time unless you use & or | operators.