please help with the error

2 ビュー (過去 30 日間)
dav
dav 2013 年 3 月 13 日
Can someone please help with the error?
clc;
clear;
warning off;
runs =100;
p=1;
yt1=[];
yt2=[];
yt3=[];
yt4=[];
yt5=[];
epsi=zeros(3000,1);
simsig=zeros(3000,1);
a0(1)=0.1; a1(1)=0.4;
for i=2:4
a0(i)=0.1; a1(i)=0.4;
end
a0(5)=0.1;a1(5)=0.4;
for i = 1:3000
m = mod(i,5);
if m==0
m=5;
end
if (i==1)
simsig(i) = a0(m)/(1-a1(m));
s=(simsig(i))^0.5;
epsi(i) = normrnd(0,1) * s;
else
simsig(i) = a0(m)+ a1(m)*(epsi(i-1))^2;
s=(simsig(i))^0.5;
epsi(i) = normrnd(0,1) * s;
end
end
epsi2=epsi.^2;
yt = epsi2(2001:3000);
ytinitial = epsi2(2001:3000);
sig = simsig(2001:3000);
ytlast=epsi(3000)^2;
ytlast2=epsi(2999)^2;
s=1;
%
for i=1:1000
m = mod(i,5);
if m==0
m=5;
end
yt(0)=0;
if m==1
yt1(s) = yt(i);
xt1(s) = yt(i-1);
elseif m ==2
yt2(s) = yt(i);
xt2(s) = yt(i-1);
elseif m==3
yt3(s)= yt(i);
xt3(s) = yt(i-1);
elseif m==4
yt4(s)= yt(i);
xt4 (s)= yt(i-1);
elseif m==5
yt5(s)= yt(i);
xt5(s)= yt(i-1);
end
s=s+1;
end
yt1(yt1==0) = [];
yt2(yt2==0) = [];
yt3(yt3==0) = [];
yt4(yt4==0) = [];
yt5(yt5==0) = [];
xt1(xt1==0) = [];
xt2(xt2==0) = [];
xt3(xt3==0) = [];
xt4(xt4==0) = [];
xt5(xt5==0) = [];
yt1=yt1';
yt2=yt2';
yt3=yt3';
yt4=yt4';
yt5=yt5';
xt1 = xt1';
xt2 = xt2';
xt3 = xt3';
xt4 = xt4';
xt5 = xt5';
ytt = [ yt1, yt2, yt3, yt4, yt5];
xtt = [ xt1, xt2, xt3, xt4, xt5];
for m = 1:5
y = ytt(:,m);
x= xtt(:,m);
%len = length(x);
C = zeros(len,p+1);
C(:,1) = 1; % The first column is for a0
%for i = 1:p %Then we create shifted columns ( p in number ) for a
% C(1+i:len,1+i) = x(1:len-i,1);
%end
C = [C x];
options =optimset('Display','off','LargeScale','off');
coef = lsqlin(C,y,[0 1],1,[],[],[0;0],[1;1],[],options);
alpha0(m) = coef(1);
ar1(m) = coef(2);
end
Error: Attempted to access yt(0); index must be a positive integer or logical. Error in test (line 67) yt(0)=0;

採用された回答

the cyclist
the cyclist 2013 年 3 月 13 日
In line 67,
yt(0)=0
you are trying to access the 0th element, but MATLAB is a 1-indexed language. You cannot use the 0th position of a vector.
  1 件のコメント
dav
dav 2013 年 3 月 13 日
thanks..

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2013 年 3 月 13 日
You can't do this:
yt(0)=0;
MATLAB is 1-based. Index counting starts at 1. There is no 0 index. If you want to set the first element to zero, do
yt(1)=0;

カテゴリ

Help Center および File ExchangePerformance and Memory についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by