您的位置:首页 > 其它

使用ujmp读取.mat文件

2015-12-22 16:31 381 查看
1)使用ujmp中的jmatio模块读取.mat文件到java程序中。



其实,ujmp主要是实现了矩阵运算,在模块core中。然后模块jmatio是复用了已有的JMatIo,对这个读取mat文件到java程序的库做了一层封装。从ujmp的官网(https://ujmp.org/)下载ujmp的jar包,但是这一个jar包并不能读取mat文件(虽然jar包内有jmatio模块),还需要下载一个JMatIo的jar包(http://pan.baidu.com/s/1jHpAtts)。将两个jar包都加入到工程中才可以从mat文件中顺利读取数据到java程序中。

操作过程如下:

2)在创建的工程中新建一个lib文件夹,将以上两个jar包拷贝到此文件夹中,必须要拷贝到项目中。比如,我之前是将两个jar包放在桌面上,但是当把jar包删除或移动之后,程序就不能运行了,很简单的道理。



3)加下来就是将两个jar包添加到工程中,以便在程序中使用这两个包中定义的类。





4)以下就是读取mat文件的代码:

/**
* Created by hfz on 2015/12/22.
*/
import org.ujmp.jmatio.ImportMatrixMAT;
import org.ujmp.core.Matrix;
import java.io.File;
import java.io.IOException;
public class test{
public  static void main(String[] args)throws IOException{
//相对路径的根目录是当前工程的目录(C:\Users\hfz\Desktop\test)。另外相对路径的起始处无“/”
ImportMatrixMAT test=new ImportMatrixMAT();
File file=new File("data/A.mat");
Matrix testMatrix=test.fromFile(file);
testMatrix.showGUI();
System.out.println("ss");
}

}


参考:

http://www.programcreek.com/java-api-examples/index.php?api=com.jmatio.io.MatFileReader

https://www.kaggle.com/c/decoding-the-human-brain/forums/t/7862/using-jmatio/65560

http://blog.madhukaraphatak.com/matfile-to-rdd/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: