"index exceeds matrix dimension" problem

1 vue (au cours des 30 derniers jours)
selin
selin le 21 Sep 2017
Commenté : selin le 21 Sep 2017
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 commentaires
Walter Roberson
Walter Roberson le 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
selin
selin le 21 Sep 2017
That worked! I really appreciate your help, thanks a lot, and have a GOOD day!

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by