I'm getting "Index in position 1 is invalid. Array indices must be positive integers or logical values." in my code
88 ビュー (過去 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!