matlab - Store std::strings in mex cell array -
inspired post, interested pass std::strings
cell array. however, mxduplicatearray
accepts mxarray
format variables. have tried transform std::string
mxarray
mxgetstring
without success.
could please create suggestion on this?
thanks!
void mexfunction(int nlhs, mxarray *plhs[],int nrhs, const mxarray *prhs[]) { std::string str ("hellooo"); const char *cstr = str.c_str(); mwsize len = 10; mxarray *mxarr = mxcreatecellmatrix(len, 1); mxarray *mxstr = mxcreatestring(""); mxgetstring(mxstr, (char*) cstr, str.length()); for(mwindex i=0; i<len; i++) { // replaced phone call mxduplicatearray here mxsetcell(mxarr, i, mxduplicatearray(mxstr)); } mxdestroyarray(mxstr); plhs[0] = mxarr; }
you cutting out phone call mxduplicatearray
(and mxdestroyarray
).
#include "mex.h" #include <string> void mexfunction(int nlhs, mxarray *plhs[], int nrhs, const mxarray *prhs[]) { std::string str("hellooo"); const char *cstr = str.c_str(); mwsize len = 10; mxarray *mxarr = mxcreatecellmatrix(len, 1); (mwindex i=0; i<len; i++) { mxsetcell(mxarr, i, mxcreatestring(cstr)); } plhs[0] = mxarr; }
untested...
matlab mex
No comments:
Post a Comment