Please expalin the error

조회 수: 15 (최근 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