Prev: tiled texture mapping
Next: crosscorrelation in matlab
From: Jacob Englander on 26 Mar 2010 18:39 I am rewriting a function which was previously implemented in MATLAB as a mex function for speed. The original function took a structure as an input and returned a structure as an output. Is there a way to pass a structure directly to a mex file, or perhaps a way to generate a C/C++ struct from a MATLAB structure?
From: James Tursa on 26 Mar 2010 20:11 "Jacob Englander" <jenglan3.removethis(a)illinois.edu> wrote in message <hojd27$nnk$1(a)fred.mathworks.com>... > I am rewriting a function which was previously implemented in MATLAB as a mex function for speed. The original function took a structure as an input and returned a structure as an output. Is there a way to pass a structure directly to a mex file, or perhaps a way to generate a C/C++ struct from a MATLAB structure? Yes. But you have to do it manually piece by piece with the mxCreateStruct, mxGetField, mxSetField, etc. API functions. There is no magic function that will take an arbitrary C/C++ struct and turn it into an mxArray for you. James Tursa
From: Máday Péter on 27 Mar 2010 16:29 Hello I was wondering if it should be possible to formulate the problem in such a way so that the parameters to the mex function would be arrays and write a wrapper function in MATLAB, that takes care of the transformation between the representations. Peter
From: James Tursa on 27 Mar 2010 17:38 Máday Péter <madapeti(a)gmail.com> wrote in message <92e333d9-0be0-4686-ac07-d323a6b1116c(a)b33g2000yqc.googlegroups.com>... > Hello > > I was wondering if it should be possible to formulate the problem in > such a way so that the parameters to the mex function would be arrays > and write a wrapper function in MATLAB, that takes care of the > transformation between the representations. > > Peter An m-file wrapper function could get at the individual structure variables and pass them along to the mex routine of course. But that doesn't really save you anything. In fact it just creates a bunch of temporary mxArray header info that you really don't need. The only advantage to this approach IMO is that it may be easier to do some error checking in the m-file vs in a mex routine. Regardless, you will still have to construct your C/C++ struct inside the mex routine ... you can't do it at the m-file level. (Is that what you are asking?). Maybe if you have a specific example of a MATLAB struct and your desired C/C++ struct I could suggest C code that would go back & forth between the two. James Tursa
From: Jacob Englander on 27 Mar 2010 20:07
Thank you, I appreciate the prompt response. I guess it will be a lot of extra work, but if there is no other way then that's what I'll do. Thanks again. |