I'm getting "Index in position 1 is invalid. Array indices must be positive integers or logical values." in my code
34 次查看(过去 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!