필터 지우기
필터 지우기

Guidance in writing mexFunction for convert.c

조회 수: 2 (최근 30일)
sidra
sidra 2013년 12월 15일
댓글: sidra 2013년 12월 24일
I have data in CSV (comma seperated value) format, i need it in the libsvm format. I found a c code to do it: http://www.csie.ntu.edu.tw/~cjlin/libsvm/faqfiles/convert.c
But i want to call this in matlab. So i need to include a mexFunction in convert.c , could anyone guide me/help me out with writing this function?

채택된 답변

James Tursa
James Tursa 2013년 12월 23일
Try putting this at the top of the file and then mex it:
// One input argument: The Filename
int main(int argc, char **argv);
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
int argc = 2;
char *argv[2];
if( nrhs == 1 && mxIsChar(prhs[0]) ) {
argv[1] = mxArrayToString(prhs[0]);
main(argc,argv);
mxFree(argv[1]);
} else {
mexErrMsgTxt("Expected one input, the filename");
}
}

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Write C Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by