Java Matlab engine Struct array fields empty

3 vues (au cours des 30 derniers jours)
Alex King
Alex King le 13 Fév 2023
Commenté : Alex King le 25 Juil 2023
I have an existing Java application using the matlab engine. The java program uses feval to pass an array of com.mathworks.matlab.types.Struct objects, a string, and a double to the running Matlab instance. This was working perfectly in the 2019b version of the matlab engine. I am required to start using the 2021b version of the engine.
Once I implemented the 2021b version of engine.jar, I started getting the com.mathworks.engine.MatlabException specifically telling me that all the struct fields were unrecogized.
After a bit of debugging in the Matlab workspace, and printing to console, I see that the size/dimensions of my struct array is being recognized, "structs = 1xN struct array with no fields". So the array structure is there, but all my data dissappears moving from Java to Matlab.
Has anyone seen this issue?
JAVA:
Struct[] data = createStructs();
double dval = 0.0;
String sval = "Some String";
engine.feval(1, "function", dval, data, sval);

Réponses (1)

Dhruv
Dhruv le 21 Avr 2023
The issue could be due to changes in the 2021b version of the Matlab engine, which may have affected the way that Struct objects are handled, try using the following approach:
  1. Check whether the Struct objects you're passing from Java to Matlab have been properly initialized and populated with data.
  2. Simplify your code and test with a basic Struct object to isolate the issue. For example, create a Struct object with just one field and pass that to Matlab to see if it is recognized properly.
  3. Try using a different method of passing data between Java and Matlab, such as using a cell array instead of a struct array. This can sometimes help to avoid compatibility issues.
Hopefully, one of these suggestions will help you resolve the issue. Please refer to the following documentation link for further guidance:
  1 commentaire
Alex King
Alex King le 25 Juil 2023
Thank you for your input. I have tried your suggestions, and the result is the same.
For a bit more context, the MatlabEngine object is created on the main thread. Other threads are calling in to the engine to run computations. Is there an issue calling the engine instance create on main thread, from another thread?
Thanks.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Call MATLAB from Java dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by