"index exceeds matrix dimension" problem
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Walter Roberson
2017년 9월 21일
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
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!