t=-2:0.01:8;
f1=[zeros(1,length(-2:0.01:0)),ones(1,length(0.01:0.01:4)),zeros(1,length(4.01:0.01:8))];
f=cos(pi*t/2).*f1;
plot(t,f)
axis([-2,8,-2,2])
t=-2:0.01:8;
f1=[zeros(1,length(-2:0.01:0)),ones(1,length(0.01:0.01:4)),zeros(1,length(4.01:0.01:8))];
f=cos(pi*t/2).*f1;
plot(t,f)
axis([-2,8,-2,2])