Subscript indices error on fitrm with NaN values

2 visualizzazioni (ultimi 30 giorni)
JP
JP il 7 Set 2017
Risposto: Abhaya il 9 Dic 2024
Hello everyone,
I am having issues with creating a repeated measures model with fitrm. The issue occurs when I choose to omit a certain amount of data points within the table and replace with NaN values. What confuses me is that the dataset works with some values replaced with NaN, however,with a certain combination of omitted data points I receive a 'Subscript indices must either be real positive integers or logicals' error.
Here is my code:
load('Bad_ranova.mat');
%Fit Repeated Measures Model
MOS_fitrm = fitrm(t,'neg2del_os-pos2del_fix~Gender*Gait_Parameter','WithinDesign',within);
%Repeated measures ANOVA
MOS_rm = ranova(MOS_fitrm,'WithinModel','BP_Condition*Step_Width');
The tables 't' and 'within' are included as attached matlab structures. Good_ranova.mat runs with no issues, Bad_ranova.mat is the same dataset but with additional data values replaced with NaN (and does not run properly).
Thanks, - JP
  2 Commenti
Leila
Leila il 19 Apr 2018
I am having exactly the same problem, any solution or advise?
Hanieh BME
Hanieh BME il 27 Apr 2018
Me as well..any solution yet?

Accedi per commentare.

Risposte (1)

Abhaya
Abhaya il 9 Dic 2024
Hi JP,
The issue you're encountering is related to how MATLAB fitrm function handles missing data. Specifically, fitrm’ function removes any rows that contain missing values (NaN) before fitting the repeated measures model.
In the Bad_ranova.mat file, the table t contains at least one NaN value in each row. When fitrm’ function is executed, it removes all rows from the t table, resulting in an empty table, which triggers the error.
To resolve this issue, you can use any workaround to handle or replace NaN values. For guidance on handling missing data in MATLAB, refer to this resource.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by