2012-11-09 51 views
1


我尝试从java中获取大数组到matlab中。 我的问题是,java程序是为了在java中运行java,所以我需要从java中导出数据并将其加载到matlab中。有人尝试过吗?导出Java对象并将其导入到matlab中

这是多远我得到: 我已经写了包含应导出

------- Export.java ------- 
import java.io.Serializable; 
public class Export implements Serializable { 
private double[][] values; 
private String description; 
public Export(String description,double[][] values){ 
    this.description=description; 
    this.values=values; 
} 
public String getDescription(){return description;} 
public double[][] getValues(){return values;} 
} 
-------------------------- 

所有值和一个主梅索德

------- StartPoint.java ------- 
public class StartPoint { 
public static void main(String[] args) { 
    Export serial= new Export("description",new double[][]{{1,2},{3,4}}); 
     OutputStream file; 
    try { 
     file = new FileOutputStream("object.ser"); 
     OutputStream buffer = new BufferedOutputStream(file); 
     ObjectOutput output = new ObjectOutputStream(buffer); 
     output.writeObject(serial); 
     output.close(); 
    } 
    catch (FileNotFoundException e) {e.printStackTrace();} 
    catch (IOException e) {e.printStackTrace();} 
    System.out.println("done"); 
    } 
} 
-------------------------- 

Accroding到http://www.weizmann.ac.il/matlab/techdoc/matlab_external/ch_java9.html的matlab-类代码应该很容易,但我不明白。所以对matlab代码的任何帮助都会很好。

谢谢

回答

1

为了便于在Matlab中导入,我建议您使用MAT-file format来编写数据。然后你将能够将文件load转换成Matlab变量。