问题是我什么都没画。
这是我的代码:
T0=2; % signal's period, in seconds
dur=20; % total signal duration, in seconds
res=0.02; % time's resolution, in seconds
t=0:res:dur-res; % time vector, which has exactly 1000 elements
duty=1/4; % duty cycle
x(dur/res)=0; % must have equal number of elements as t, plot won't work otherwise
for t=0:res:dur-res % period is 2s, so for t between 0 and 0.5 , 2 and 2.5, 4 and 4.5, etc (the 'desired interval'), all x values will be 1, and the rest will be 0
mlt=1;
if t<=mlt*T0*duty % calculating if t is in desired interval
x(round(1+(t/res)))=1; % using round because I have some error despite the number (t/res) being always integer, I add 1 so the index is not 0
else x(round(1+(t/res)))=0;
end
if mod(t,2)==0 % if t enters the desired interval
mlt=mlt+4; % going to the next period's desired interval. just trying to make it work for a period of 2 seconds now, will figure out a formula later
end
end
s=sin(x*pi/2); % if x=0, the sine is 0, if x=1, the sine is 1. using sine because I need it to be a continuous function
plot(t,s);
axis ([0 20 0 1]);
我希望评论是全面的。 我是一个非常缺乏经验的MATLAB用户,我一直只使用它一周。 另外,如果你知道一种更简单的方法来解决我的运动(是的,这是家庭作业),我很乐意分析它。