index out of bounds because size(IC)=[0,1]

Hi I'm trying to execute a program but i keep getting this error: "Attempted to access IC(1,1); index out of bounds because size(IC)=[0,1].
Error in Hansen_2reg_v2>estimation_2reg (line 325) LB_IC_gam=IC(1,1);
I do not understand what does it mean. Is someone ready to help me?
here is the code:
LR=zeros(length(def),2); % size(def)= 825*1
Var_Res_opt=rss_opt/(N*(T-1)); % Residual Variance
for i=1:length(def);
gam=def(i);
x_gam=[X.*repmat((Q<gam),1,K) X.*repmat((Q>=gam),1,K)];
x_cent=zeros(T*N,K*2);
for indic_k=1:K*2
mk=repmat(mean(reshape(x_gam(:,indic_k),T,N)),T,1);
x_cent(:,indic_k)=x_gam(:,indic_k)-mk(:);
end
coef_cent=((x_cent)'*x_cent)^(-1)*x_cent'*y_cent;
mk=[];
for indic_k=1:K*2;
mk=[mk mean(reshape(x_gam(:,indic_k),T,N))'];
end
e=y_cent-x_cent*coef_cent;
rss=e'*e;
LR(i,1)=gam;
LR(i,2)=(rss-rss_opt)/Var_Res_opt;
end
C_alpha=-2*log(1-sqrt(1-alpha));
IC=LR((LR(:,2)<=C_alpha),1);
LB_IC_gam=IC(1,1);
UP_IC_gam=IC(end,1);
esti.x=x_opt;
esti.gam=gam_opt;
esti.IC_gam=[LB_IC_gam UP_IC_gam];
esti.effets_fixes = effets_fixes2 ;
esti.coef=coef_cent2;
esti.coef_stat=coef_stat;
esti.residus=e2;
esti.rss=rss_opt;
esti.var_res=Var_Res_opt;

 Accepted Answer

José-Luis
José-Luis on 16 May 2013
Edited: José-Luis on 16 May 2013
Please learn to use the debugger.
doc dbstop
It could save you a lot of time in the figure and is a very good tool to troubleshoot the problem you are describing. It is probably easier to use with the gui, instead of using dbstop.
You could pause before the line that's giving you trouble and look at IC. If you do not understand indexing, it is a good idea to look at the Getting started part of the documentation.
In this case the error message is telling you that IC is in fact empty (size[0,1]) and that you are trying to access its first element. Since IC is defined as follows:
IC=LR((LR(:,2)<=C_alpha),1);
it implies the no LR(:,2) values are inferior or equal to C_alpha.

More Answers (2)

Jan
Jan on 16 May 2013
Edited: Jan on 16 May 2013
The error messag means:
Attempted to access IC(1,1)
You try to access IC(1, 1) in line line 325. But:
index out of bounds because size(IC)=[0,1].
This means, that IC is an empty array. It has the domensions [0 x 1], but it contains exactly the same number of elements as a [0 x 0] array.
This happens, because the previous line:
IC = LR((LR(:,2)<=C_alpha),1)
does not find matching elements: All LR(:,2) are smaller than C_alpha.
Stephanie
Stephanie on 16 May 2013
Thank you for answers. In fact i found that Var_Res_opt is not a number (NaN) so LR(i,2)=(rss-rss_opt)/Var_Res_opt is not a number either. That's why we have the no LR(:,2) values are inferior or equal to C_alpha. Thanks again for your help

1 Comment

hi please telle me why you are correct this problem?

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!