Please expalin the error
1 view (last 30 days)
Show older comments
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 Comment
Youssef Khmou
on 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 !!
Accepted Answer
Walter Roberson
on 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".
0 Comments
More Answers (0)
See Also
Categories
Find more on Operators and Elementary Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!