Please expalin the error

17 visualizzazioni (ultimi 30 giorni)
dav
dav il 25 Feb 2013
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 Commento
Youssef  Khmou
Youssef Khmou il 25 Feb 2013
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 !!

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 25 Feb 2013
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".

Più risposte (0)

Categorie

Scopri di più su Operators and Elementary Operations in Help Center e File Exchange

Tag

Non è stata ancora inserito alcun tag.

Community Treasure Hunt

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

Start Hunting!

Translated by