2012-11-09 57 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變量。