用matlab中libsvm进行svm训练后,需要将模型文件保存下来,网上找了好久终于找到一个能用的了。
主要参考:https://www.tuicool.com/articles/QvAr22
本人版本:MATLAB R2016a,libsvm3.23
该版本输出的模型结构体域有11个,因此不需要像原博客修改代码。可直接使用svm_savemodel.c,如下:
#include "../svm.h"
#include "mex.h"
#include "svm_model_matlab.h"
static void fake_answer(mxArray *plhs[])
{
plhs[0] = mxCreateDoubleMatrix(0, 0, mxREAL);
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
struct svm_model *model;
char *filename;
const char *error_msg;
int status;
// check input
if(nrhs != 2) {
mexPrintf("Usage: svm_savemodel(model, 'filename');\n");
fake_answer(plhs);
return;
}
if(!mxIsStruct(prhs[0])) {
mexPrintf("model file should be a struct array\n");
fake_answe