NaN in mot files [API]
Posted: Wed Mar 01, 2023 6:18 am
Hi all,
I'm working with the API (OpenSim 4.4) in Matlab and when I read my c3d with osimC3D(c3dpath,1) I get NaNs in the CoP, therefore forceTable = c3d.getTable_forces() has NaNs that get written to my mot when I use c3d.writeMOT. Is there a way to fix this? I couldn't find any answer in the forum...
I also tried to modify the c3d.writeMOT method/function: I manage to get the CoP columns in Matlab and modify them (fixing the NaNs in Matlab), but then I have problems writing them back in the forces TimeSeriesTableVec3. Is there a smart way to do that? I'm not too familiar with OOP and I was not able to just update the position columns, how do you do that? At the moment I'm using the following piece of code, but it's not great
for i = 0 : labels.size() - 1
% Get the label as a string
label = char(labels.get(i));
%% interpolate for NaN
NaNmatrix=forces.getDependentColumn(label).getAsMat;
len_vec= 1:size(NaNmatrix,1);
vec_x=fillmissing(NaNmatrix(:,1),'linear','SamplePoints',len_vec);
vec_y=fillmissing(NaNmatrix(:,2),'linear','SamplePoints',len_vec);
vec_z=fillmissing(NaNmatrix(:,3),'linear','SamplePoints',len_vec);
vec3matrix=[vec_x, vec_y, vec_z];
aa=VectorVec3().createFromMat(vec3matrix);
try
forces.removeColumn(label)
catch
%throws error but it works
end
forces.appendColumn(label,aa)
end
It's also worth to mention that when I use removeColumn I get the following error (even if it seems to work just fine):
Java exception occurred:
java.lang.RuntimeException: Key = units expected = 11 received = 12
Thrown at DataTable.h:1629 in validateDependentsMetaData().
at org.opensim.modeling.opensimCommonJNI.DataTableVec3_removeColumn(Native Method)
at org.opensim.modeling.DataTableVec3.removeColumn(DataTableVec3.java:357)
Thanks in advance if anyone could help me!
I'm working with the API (OpenSim 4.4) in Matlab and when I read my c3d with osimC3D(c3dpath,1) I get NaNs in the CoP, therefore forceTable = c3d.getTable_forces() has NaNs that get written to my mot when I use c3d.writeMOT. Is there a way to fix this? I couldn't find any answer in the forum...
I also tried to modify the c3d.writeMOT method/function: I manage to get the CoP columns in Matlab and modify them (fixing the NaNs in Matlab), but then I have problems writing them back in the forces TimeSeriesTableVec3. Is there a smart way to do that? I'm not too familiar with OOP and I was not able to just update the position columns, how do you do that? At the moment I'm using the following piece of code, but it's not great
for i = 0 : labels.size() - 1
% Get the label as a string
label = char(labels.get(i));
%% interpolate for NaN
NaNmatrix=forces.getDependentColumn(label).getAsMat;
len_vec= 1:size(NaNmatrix,1);
vec_x=fillmissing(NaNmatrix(:,1),'linear','SamplePoints',len_vec);
vec_y=fillmissing(NaNmatrix(:,2),'linear','SamplePoints',len_vec);
vec_z=fillmissing(NaNmatrix(:,3),'linear','SamplePoints',len_vec);
vec3matrix=[vec_x, vec_y, vec_z];
aa=VectorVec3().createFromMat(vec3matrix);
try
forces.removeColumn(label)
catch
%throws error but it works
end
forces.appendColumn(label,aa)
end
It's also worth to mention that when I use removeColumn I get the following error (even if it seems to work just fine):
Java exception occurred:
java.lang.RuntimeException: Key = units expected = 11 received = 12
Thrown at DataTable.h:1629 in validateDependentsMetaData().
at org.opensim.modeling.opensimCommonJNI.DataTableVec3_removeColumn(Native Method)
at org.opensim.modeling.DataTableVec3.removeColumn(DataTableVec3.java:357)
Thanks in advance if anyone could help me!