I'm getting "Index in position 1 is invalid. Array indices must be positive integers or logical values." in my code
조회 수: 94 (최근 30일)
이전 댓글 표시
Hi everyone, I'm developing a code that needs to use a linear mixed effects regression. When a I try to use a table in this tool im getting an error message "Index in position 1 is invalid. Array indices must be positive integers or logical values." Can you help me to solve it?
data_resi_inter = readtable('Residuales_inter.xlsx');
data_resi_intra = readtable('Residuales_intra.xlsx');
%% Regresion y obtencion de Residuales Inter evento (Interplaca)
lme_inter = fitlme(data_resi_inter,'res_PGA ~ 1 + (1|EQID)');
[beta_inter,betanames_inter,Fstats_inter] = fixedEffects(lme_inter);
c0_inter = beta_inter;
SE(i,1) = Fstats_inter.SE;
[B_inter,Bnames_inter,Rstats_inter] = randomEffects(lme_inter);
eta_inter = B_inter;
error_B_inter = (Rstats_inter.Upper-Rstats_inter.Lower)/2;
[psi_inter,mse_inter,stats_inter] = covarianceParameters(lme_inter)
댓글 수: 1
Shivam
2024년 9월 4일
I can better help you if you can attach the data files. It will help me reproducing the error.
채택된 답변
Zinea
2024년 9월 4일
The error message you're encountering indicates that there's an issue with the index 'i' in the following line:
SE(i,1) = Fstats_inter.SE;
This suggests that 'i' is either undefined, zero, or negative at the time this line is executed. Array indices in MATLAB must be positive integers. It is necessary to ensure that 'i' is defined and initialized before you use it.
댓글 수: 2
Stephen23
2024년 9월 4일
"This suggests that 'i' is either undefined, zero, or negative at the time this line is executed"
An undefined variable would throw a very different error, e.g.:
M = rand(2,3);
M(k,3)
추가 답변 (1개)
Shivam
2024년 9월 4일
편집: Shivam
2024년 9월 4일
Hi Ivan,
Upon investigation of the error through the provided script and the excel files, I see that you are trying to index into SE with paramters as i and 1.
Please know that since first parameter i is not defined in the script before that line (assuming the provided script is the only code), the first parameter is considered to be a complex no. i.e.
0.0000 + 1.0000i
Please ensure that you use the correct positive (>0) index parameter to save the Fstats_inter.SE data. e.g.
SE(1,1) = Fstats_inter.SE
I hope it resolved your query.
참고 항목
카테고리
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!