ok guys, feel if i'm falling rabbit hole...
to build interface matlab-mex receives several different messages consist of complicated c-structs, want create corresponding mex-structs each in different functions.
is somehow possible pass mxarrays contain fields user defined functions mexfunction()?
i created functions should called inside of mexfunctions() should pass filled mxarray datatypes mexfunction() pointers didn't work.
e.g.
mxarray* createfoo(); or
void createfoo(mxarray* mydata); inside mexfunction() these createfoo() functions couldn't pass created data pointers function. inside them, creating of data did work, pointers returned changed mysteriously because of e.g. mydata = mxcreatedoublematrix().
the compiler visual studio 2010, matlab 2011b.
it possible directly write workspace inside functions, bad style.
ok, should never again ask question without minimal example. simple problem was, forgot return *mxarray...
both possibilities pass mxarray work should:
a) return mxarray*
mxarray* createfoo() { mxarray* myarray; myarray = mxcreatedoublematrix(1,1,mxreal); *mxgetpr(myarray) = 3; mexprintf("*mxgetpr(myarray)= %f\n", *mxgetpr(myarray)); // 3 return myarray; } b) reference mxarray **
void createfooreference(mxarray** myarray) { *myarray = mxcreatedoublematrix(1,1,mxreal); *mxgetpr(*myarray) = 4; mexprintf("pointer: *mxgetpr(*myarray)= %f\n", *mxgetpr(*myarray)); // 4 } now it's possible call functions , return values matlab:
void mexfunction( int nlhs, mxarray *plhs[], int nrhs, const mxarray prhs[]) { mxarray *mexa, *mexb; mexa = createfoo(); plhs[0] = mexa; // 3 createfooreference(&mexb) plhs[1] = mexb; // 4 }
Comments
Post a Comment