我試圖符合以下通過下面的模型,這意味着正弦模型是確定性模型+白噪聲:飛度正弦模型
function [x]=generate(N,m,A3)
f1=100;
f2=200;
T=1/f1;
for t=0:N*T/m:N*T
WN(t)=rand(1,t)*2-1;
x(t)=20*sin(2*pi*f1*t)+30*cos(2*pi*f2*t)+A3*WN(t);
end;
但是當我運行使用下面的命令:
generate(100,10,40)
我得到以下錯誤:
Subscript indices must either be real positive integers or logicals.
Error in generate (line 6)
WN(t)=rand(1,t)*2-1;
那麼,怎麼了?據我所知,我可以使用rand
功能的兩個參數嗎?這裏有什麼問題?
更新: 這就是我已經固定它
function [ x]=generate(N,m,A3)
WN=[];
f1=100;
f2=200;
T=1/f1;
k=0;
for t=0:N*T/m:N*T
% WN(k)=rand(1,1)*2-1;
% x(k)=20*sin(2*pi*f1*t)+30*cos(2*pi*f2*t)+A3*WN(k);
%k=k+1;
WN=rand*2-1;
disp(20*sin(2*pi*f1*t)+30*cos(2*pi*f2*t)+A3*WN);
end;
,並導致
generate(1000,10,40)
25.4143
-1.4678
66.9518
-9.6293
51.9928
55.3843
59.4956
-3.2451
21.9826
10.7896
54.0055
這樣看來,t'的'至少一個值是不是正整數... – 2013-03-21 10:48:27
這怎麼可能t從正面積極的變化? – 2013-03-21 10:50:21
爲什麼不打印't'的值並確認? – 2013-03-21 10:51:24