看板 C_and_CPP 關於我們 聯絡資訊
剛好這邊有些資料,參考看看 Importing and Exporting MAT-File Data The MATLAB C++ Math Library provides two functions, load() and save(), that let you import mwArray variables from a MAT-file and export mwArray variables to a MAT-file. Because MATLAB also reads and writes MAT-files, you can use load() and save() to share data with MATLAB applications or with other applications developed with the MATLAB C++ or C Math Library. AMAT-file is a binary,machine-dependent file. However, it can be transported between machines because of a machine signature in its file header. The MATLAB C++Math Library checks the signature when it loads variables from a MAT-file and, if a signature indicates that a file is foreign (file was saved on a different architecture than the one on which it is being loaded), performs the necessary conversion. Example Program: Using load() and save() #include <stdlib.h> #include "matlab.hpp" int main(void) { try { mwArray x, y, z, a, b, c; x = rand(4,4); y = magic(7); z = eig(x); // Save (and name) the variables. save("ex5.mat", "x", x, "y", y, "z", z); // Load the named variables. load("ex5.mat", "x", &a, "y", &b, "z", &c); // Check to be sure the variables are equal. if (tobool(a == x) && tobool(b == y) && tobool(c == z)) { cout << "Success: all variables equal." << endl; } else { cout << "Failure: loaded values not equal to saved values." << endl; } } catch (mwException &ex) { cout << ex << endl; } return(EXIT_SUCCESS); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.118.207.32