I'm getting "Index in position 1 is invalid. Array indices must be positive integers or logical values." in my code
53 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Shivam
el 4 de Sept. de 2024
I can better help you if you can attach the data files. It will help me reproducing the error.
Respuesta aceptada
Zinea
el 4 de Sept. de 2024
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 comentarios
Stephen23
el 4 de Sept. de 2024
"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)
Más respuestas (1)
Shivam
el 4 de Sept. de 2024
Editada: Shivam
el 4 de Sept. de 2024
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.
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!