How to access variables saved in .mat file in a built jar file by MATLAB Builder JA?

这一生的挚爱 提交于 2020-01-05 13:37:10

问题


I have been so distracted by the whole amount of pages documenting MATLAB Builder JA and running very low on time.

My question is, how could I load a .mat file and access all variables of it?

What I did is, I made my own class with all functions I need in MATLAB Builder JA, then added the .mat file I need and built all that.

I made a java project now and instantiated an object of my class but now I want to access the variables saved in the .mat file in Java to pass it to the object's methods?


回答1:


Assalmo Alykom

The best way to do it as Amro suggested is to make a matlab function that loads the MAT file itself.

    function out= loadMAT(nameOfMAT)
       out=load(nameOfMAT);

This would load the MAT and returns it as MWStructArray class in Java (It's inside javabuilder.jar). You can do this in JAVA to access the object inside of the MAT file.

List rhs=new ArrayList();
rhs.add(new File("matlab-mat-file-name.mat").getAbsolutePath());    
Object[] ob=fis.loadMAT(1, rhs.get(0));

ob has all the variables you want!

Salam!



来源:https://stackoverflow.com/questions/11255627/how-to-access-variables-saved-in-mat-file-in-a-built-jar-file-by-matlab-builder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!