フィルターのクリア

How to read a 'CompactSVMModel' saved in a .mat file from a C++/Qt program

12 ビュー (過去 30 日間)
MahnnUser
MahnnUser 約16時間 前
I tried to save a machine learning model into a .mat file, and then read it from a Qt/C++ application. Following the documentation, I managed to read files containing basic types like double or int. As my model is of type 'classreg.learning.classif.CompactClassificationSVM', I wonder if it is still possible to read it.
As and example, i saved this iosnosphere model on matlab
load ionosphere
SVMModel = fitcsvm(X,Y,'Standardize',true,'ClassNames',{'b','g'})
CompactSVMModel = compact(SVMModel)
save("CompactSVMModel.mat", "CompactSVMModel")
I imported the relevant library in the CMakeLists.txt
find_package(Matlab "x.xx" EXACT COMPONENTS "MX_LIBRARY" "MAT_LIBRARY" "DATAARRAY_LIBRARY" )
target_link_libraries(target PRIVATE Matlab::mat )
I used the "mat.h" library to open and read the data.
#include "mat.h"
int main () {
std::string stdFilename = "/filepath/CompactSVMModel.mat";
const char *variableName = "CompactSVMModel";
// Open the MAT-File
MATFile *matFile = matOpen(stdFilename.c_str(), "r");
if (!matFile) {
qDebug() << "Error opening MAT file: " << stdFilename;
}
// Read the variable from the MAT-File
mxArray *dataArray = matGetVariable(matFile, variableName);
if (!dataArray) {
qDebug() << "Error reading variable: " << variableName << " from MAT file: " << stdFilename;
}
...
// read a save the diffrent fields into containers
return 0;
}
At the first if statement, matFile is NULL.

回答 (0 件)

製品


リリース

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by