MATLAB: Can I not call a function inside another function?? getting “Output argument “ytest” (and maybe others) not assigned during call to “test>piecewise1″.” as error

calling functionsdspfunctionspiecewise functions

x = linspace(0,1);
ytest = piecewise1(x);
plot(x,ytest)
function ytest = piecewise1(x)
if 0<x<0.04
ytest = piecewise(x);
elseif 0.04<x<0.08
ytest = piecewise(x-0.04);
elseif 0.08<x<0.1
ytest = piecewise(x-0.08);
elseif 0.1<x<1
ytest = 0;
end
end
function w = piecewise(x);
w(0<=x & x<0.005) = 6;
x1 = x(0.005<=x & x<=0.015);
w(0.005<=x & x<=0.015)= (60000*(x1.^2)-1800*x1+13.5);
x2 = x(0.015<=x & x<=0.025);
w(0.015<=x & x<=0.025) = 0;
x3 = x(0.025<=x & x<=0.035);
w(0.025<=x & x<=0.035) = -3*sin(300*3.14*(x3-0.025));
x4 = x(0.035<=x & x<=0.04);
w(0.035<=x & x<=0.04) = 6*sin(100*3.14*(x4-0.035));
end

Best Answer

if 0<x<0.04
means
if ((0<x)<0.04)
The first part, 0<x, returns 0 (false) or 1 (true). That 0 or 1 is then compared to 0.04, and the result of that can only be true if the first test returned 0, which would be the case if 0<x was false. So that line is a fancy way to write
if x <= 0