Please expalin the error

7 次查看(过去 30 天)
dav
dav 2013-2-25
Hello,
I have the following funtion:
function Beta = arima(y, p, q, C, sigma)
if nargin < 4
C = 0;
end
if nargin < 5
sigma = 1;
end
y = y(:);
N = length(y);
e = sigma * randn(N, 1);
Y = y - e;
% By = y(1:end-1) y(1:end-2) ... y(:, end-p)
By = arrayfun(@(j) [zeros(j,1); y(1:end-j)], 1:p, 'UniformOutput' , false); By = [By{:}];
Be = arrayfun(@(j) [zeros(j,1); e(1:end-j)], 1:q, 'UniformOutput' , false); Be = [Be{:}];
if C == 0
cvec = [];
else
cvec = ones(N,1);
end
X = [cvec By Be];
Beta = Y\X;
end
and I am trying to call it in the following code:
a0 = 0.05; a1 = 0.1; b1 = 0.85;
epsi=zeros(3000,1);
simsig=zeros(3000,1);
for i = 1:3000
if (i==1)
simsig(i) = a0 ;
s=(simsig(i))^0.5;
epsi(i) = normrnd(0,1) * s;
else
simsig(i) = a0+ a1*(epsi(i-1))^2+ b1*simsig(i-1);
s=(simsig(i))^0.5;
epsi(i) = normrnd(0,1) * s;
end
end
yt1=epsi.^2;
Beta = arima(yt1, 1, 1, 0.05, 1);
But I get the following error msg:
Attempt to execute SCRIPT arima as a function:
F:\MATLAB\arima.m
Error in aa (line 21)
beta = arima(yt1, 1, 1, 0.05, 1);*
I have both saved in the same folder. What should I do?
Thanks
  1 个评论
Youssef  Khmou
Youssef Khmou 2013-2-25
hi, i just tried them ( both saved in the Desktop ) and they work both fine, i can not figure out where that error came from !!

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2013-2-25
The function you show first must be stored in a file named arima.m and it needs to be stored in a directory that is "before" F:\MATLAB\arima.m in your MATLAB path.
You probably have two arima.m, one in your current directory and the other in F:\MATLAB\arima.m
There is another possibility, and that is that you might have placed executable code above the part you show for the function, inside arima.m . The first non-empty non-comment line in a function file must start with "function".

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operators and Elementary Operations 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by