如何通过MATLAB Builder JA访问在生成的jar文件中保存在.mat文件中的变量? [英] How to access variables saved in .mat file in a built jar file by MATLAB Builder JA?

查看:166
本文介绍了如何通过MATLAB Builder JA访问在生成的jar文件中保存在.mat文件中的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对记录MATLAB Builder JA的全部页面分心,而且运行时间非常短.

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

我的问题是,如何加载.mat文件并访问其中的所有变量?

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

我所做的是,我在MATLAB Builder JA中创建了自己需要的所有函数的类,然后添加了我需要的.mat文件并构建了所有这些文件.

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.

我现在创建了一个Java项目并实例化了我的类的对象,但是现在我想访问Java中.mat文件中保存的变量,以将其传递给对象的方法?

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?

推荐答案

阿萨尔莫(Asalmo Alykom)

Assalmo Alykom

按照Amro的建议,最好的方法是制作一个可加载MAT文件本身的matlab函数.

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);

这将加载MAT并将其作为Java中的MWStructArray类返回(位于javabuilder.jar中). 您可以在JAVA中执行此操作,以访问MAT文件中的对象.

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拥有您想要的所有变量!

ob has all the variables you want!

萨拉姆!

这篇关于如何通过MATLAB Builder JA访问在生成的jar文件中保存在.mat文件中的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆