"index exceeds matrix dimension" problem
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
When I run the code below without an r-loop, I don't have any problems. But when I try to run it like as what is written below, MATLAB is giving "Index exceeds matrix dimension" error. Is there anyone who can help me with this? Thanks in advance!
heye=eye(length(b0),length(b0));
for t=1:length(b0)
heye(t,t)=delt(t);
end
betas1=zeros(length(b0),length(b0));
for r=1:length(b0)
betas1(:,r)=b0;
end
betas1=betas1+heye;
lf1=zeros(numobs,length(b));
%keyboard;
for r=1:length(b0)
b0=betas1(:,r);
A=zeros(numobs,1);
B=zeros(numobs,1);
for i=1:numobs
if c(i)==1
funnon=@(x)exp(-x*b0(1)*t(i))./x;
qnon=integral(funnon,1,1+b0(2)*1);
if qnon~=0
B(i)=qnon;
else
B(i)=0.0000000000000000000000000000000000000000000000001;
end
elseif c(i)==2
funint=@(x)(exp(-x*b0(1)*t1(i))-exp(-x*b0(1)*t2(i)))./x.^2;
qint=integral(funint, 1, 1+b0(2)*1);
if qint~=0
B(i)=qint;
else
B(i)=0.0000000000000000000000000000000000000000000000001;
end
%B(i)=qint;
else
funr=@(x)exp(-x*b0(1)*t(i))./x.^2;
qr=integral(funr, 1, 1+b0(2)*1);
if qr~=0
B(i)=qr;
else
B(i)=0.0000000000000000000000000000000000000000000000001;
end
%B(i);
end
end
for i=1:numobs
if c(i)==1
y(i) = log(b0(1))+log(1+b0(2)*1)-log(b0(2)*1)+log(B(i));
A(i)=y(i);
elseif c(i)==2
y(i)=log(1+b0(2)*1)-log(b0(2)*1)+log(B(i));
A(i)=y(i);
else
y(i)=log(1+b0(2)*1)-log(b0(2)*1)+log(B(i));
A(i)=y(i);
end
end
lf1(:,r)=A;
end
4 Kommentare
Walter Roberson
am 21 Sep. 2017
t is not a 35781 x 1 vector. You have
for t=1:length(b0)
heye(t,t)=delt(t);
end
which is overwriting t with a scalar
Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!