t=0:2*pi/1000:2*pi;y1=sin(t);y2=.2*sin(2*t);y3=.1*sin(3*t+.25*pi);y4=.15*sin(4*t+.3*pi);y5=.8*sin(5*t+.3*pi);
y=y1+y2+y3+y4+y5;
x=y;
figure(1)
plot(t,x);
h=fft(x,1001);
ang=angle(h);
z=abs(h)/500;
yy=0*sin(t);
for i=1:950;
yy=yy+z(i)*cos((i-1)*t+ang(i));
end
hold on
plot(t,yy,'r')
f0=z(1)*cos(0*t+ang(1));
f1=z(2)*cos(1*t+ang(2));
f2=z(3)*cos(2*t+ang(3));
f3=z(4)*cos(3*t+ang(4));
f4=z(5)*cos(4*t+ang(5));
f5=z(6)*cos(5*t+ang(6));
f6=z(7)*cos(6*t+ang(7));
f7=z(8)*cos(7*t+ang(8));
f8=z(9)*cos(8*t+ang(9));
f9=z(10)*cos(9*t+ang(10));
主要是f0到f9的算法,且最后能画出f0到f9的图形
------解决方案--------------------------------------------------------
给你个提示,eval函数
eval
Execute string containing MATLAB expression
Syntax
eval(expression)
[a1, a2, a3, ...] = eval('myfun(b1, b2, b3, ...)')
------解决方案--------------------------------------------------------
楼上说得对,可以用for循环来做,用eval来调用相应的字符串函数!