index out of bounds because size(IC)=[0,1]
Mostrar comentarios más antiguos
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;
Respuesta aceptada
Más respuestas (2)
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
el 16 de Mayo de 2013
0 votos
1 comentario
Hayet Ben Hamida
el 7 de Jun. de 2017
hi please telle me why you are correct this problem?
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!