f



Writing C MEX S-Function from existing Matlab C MEX function

I have an existing Matlab C MEX function (walkode.dll) that 
returns state derivatives when called by ode23s
(walkode,...) from a regular Matlab script or the command 
line. I would like to incorporate this into a Simulink 
model, and have done so using a Level 1 M-file S-function, 
which called walkode in the mdlDerivatives subfunction. 
However this model runs very slowly.

I would prefer to rewrite (recompile?) my .dll as a C MEX S-
function (using sfuntmpl_doc.c I believe), but I am unsure 
as how to go about doing so. This is where my understanding 
(or more aptly, misunderstanding) of C, MEX and C-MEX comes 
into play. The original source (walkode.c) uses mexFunction 
to perform error checking, initialization, and in 
general "run" the program.

Is it merely a matter of reassigning the statements in 
mexFunction to the proper function calls 
(mdlInitializeSizes, mdlOutputs, mdlDerivatives, etc.) in 
sfuntmpl.c? And adding all the required libraries as well. 
Mostly these statements are no more than calls to create 
input and output pointers and pass them as arguments to my 
C subroutine, as well as error checking on input 
dimensions. And then there is the single line of code that 
calls my subroutine.

I've been though most of the Matlab documentation, but I 
still haven't had that "Aha!" moment. Any guidance is 
greatly appreciated. Thanks.


0
coultert (3)
7/16/2008 7:22:02 PM
comp.soft-sys.matlab 211264 articles. 25 followers. lunamoonmoon (257) is leader. Post Follow

0 Replies
1202 Views

Similar Articles

[PageSpeed] 49

Reply: