问题
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