1

到目前为止我的代码(基于此条目)但它不起作用:

MatFileReader matfilereader = new MatFileReader("C:\\data\\Freebase\\initEmbed.mat");
System.out.println(matfilereader.getData().get(0) + "name: "+matfilereader.getMLArray("words").getSize());
System.out.println("new "+matfilereader.getMLArray("words"));
MLArray words = matfilereader.getMLArray("words");
System.out.println(words.contentToString().substring(0, 100));
MLChar j = (MLChar) matfilereader.getMLArray("words");

我的输出:

[1x91898  cell array]name: 91898
new [1x91898  cell array]
words = 
    [1x9  char array]   [1x3  char array]   [1x1  char array]   [1x1  char array]   [1x2  char array]   

Exception in thread "main" java.lang.ClassCastException: com.jmatio.types.MLCell cannot be cast to com.jmatio.types.MLChar
    at NTN.Run_NTN.main(Run_NTN.java:91)

如何将此matlab文件的单词加载到java数组中?

4

1 回答 1

1

我对matLab一无所知,但异常似乎很清楚。您正在将 a 投射MLCell到 aa MLChar。" getMLArray" 必须返回一个MLCell. 我会投到MLCell第一个

MLCell mlCell = (MLCell) matfilereader.getMLArray("words");

然后使用该类型上可用的任何方法来获取MLChar.

于 2015-04-20T13:38:12.380 回答