How can I replace NaN's in a java array with 0?
3 ビュー (過去 30 日間)
古いコメントを表示
I am using a pre-built Matlab code to import a motion capture (.c3d) file into a simulation program (OpenSim). It works just fine for the most part. As part of the import, it grabs the data and makes it into a Java array. However, this carries over NaN's and I need them to be zero, as a NaN causes the data analysis to fall apart in the simulation. I have tried and failed to convert those values to zero prior to importing them into MatLab. Here is an example of the code and output in question.
forceTable = c3d.getTable_forces();
I know that this does not mean much without context, but this part of the code brings in the Java table, which works just fine.
The table looks like the attached pictures.



What I need to do is replace all instances of nan and -nan(ind) with 0 in order to make it work downstream.
Is there an easy way to do this, or am I just wasting my time? I have tried lines such as
forceTable(forceTable==java.lang.Long(nan))=java.lang.Long(0);
along with any combination of the Java types that I think might work.
This may not be enough to go on, but let me know if there's anything else I can do to provide context.
Thanks.
1 件のコメント
Guillaume
2019 年 3 月 4 日
This is all going to depend on the interface of that TimeSeriesTableVec3 Java class. If you don't have access to the documentation for that class then it's going to be difficult. Possibly, you could have an idea of the interface with:
methodsview(forceTable)
but nothing beats the documentation.
At the moment, all you have is an object that contains some data. You will need to extract the data you want from the object. In Java, it's usually a getXXXX method. Once you've got that data, as an array of number, it will be trivial to replace the NaN. After that, you'd have to put the data back in the object (with a setXXXX method) or recreate the object from all its other properties and your nan-less array. For all of that, you need to know the actual interface.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Call Java from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!