You can load the data matrix into MATLAB like any regular MAT file:
load data.mat
then use the MEX function libsvmwrite , which comes with the libsvm MATLAB interface, to write it to the so-called "sparse" format:
libsvmwrite('data.txt', label_vector, instance_matrix)
If you are talking about trained models, not about data, a quick search showed this page (I have not personally tested it).
EDIT:
Well, it looks like the code I mentioned needs some tweaking. Below is my modified version. I tested it using the latest libSVM-3.12, with VS2010 as the compiler:
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;
Assuming you compiled the above MEX file, here is a usage example:
[labels, data] = libsvmread('./heart_scale'); model = svmtrain(labels, data, '-c 1 -g 0.07'); svm_savemodel(model, 'mymodel.model');
The created text file looks like this:
mymodel.model
svm_type c_svc kernel_type rbf gamma 0.07 nr_class 2 total_sv 130 rho 0.426412 label 1 -1 nr_sv 63 67 SV 1 1:0.166667 2:1 3:-0.333333 4:-0.433962 5:-0.383562 6:-1 7:-1 8:0.0687023 9:-1 10:-0.903226 11:-1 12:-1 13:1 0.6646947579781318 1:0.125 2:1 3:0.333333 4:-0.320755 5:-0.406393 6:1 7:1 8:0.0839695 9:1 10:-0.806452 12:-0.333333 13:0.5 . .