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,...

Hi, I am using C MEX S-function in SIMULINK. This S-function calls a Compiled C-MEX file "emdc.dll" using the command "mexCallMATLAB", which is shown feasible in "http://www.mathworks.com/support/solutions/en/data/1-22EA0J/?solution=1-22EA0J". The "emdc.dll" works well when called in the command windows. Also, this s-function can be compiled normally with "mex". However, when running the S-function in SIMULINK, "Segmentation violation" was notified. I have been looking for a lot of posts for two more days with the problem still unsol...

Here is my mex code: void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){ char errBuff[1]={'A'}; //create mxArray pointer mxArray *mxerr; //copy errBuff to mxArray mxerr = mxCreateString(errBuff); //initialize mxArray with errBuff char array, return to pointer //call matlab function mexCallMATLAB(0,NULL, 1,mxerr, "errorCatcher"); //destroy mxArray mxDestroyArray(mxerr); //destroy mxArray printf("destroyed mex array\n"); }//end of mexFunction errorCatcher accepts string inp...

I have a C-mex s-function in which I need to use a counter variable that maintains a certain value for N iterations of my mdlOutputs( ) function, and then gets incremented. Declaring this counter variable within mdlOutputs() isn't feasible, since every time this function is called, the variable will be re-declared and re-initialized, instead of maintaining a persistent value through time. I have tried declaring the variable within mdlInitializeConditions() (as well as mdlStart(), out of curiosity), but when I attempt to print its value within mdlOutputs(), I get a compiler error that t...

please tell me the difference b/w S-function and Embedded matlab function "Binu Baby" <binu_k_baby@yahoo.co.in> wrote in message news:guu39t$m6g$1@fred.mathworks.com... > please tell me the difference b/w S-function and Embedded matlab function Embedded MATLAB allows to include MATLAB code in a Simulink model. When you double-click on an Embedded MATLAB block, it opens up the MATLAB editor, and you can just copy and paste your MATLAB code here. If you restrict your code to the (growing) Embedded MATLAB subset (see http://www.mathworks.com/access/helpdesk/help/toolbox...

Hi to everybody, I created the file forward.dll using the command: mex -DWIN32 -output forward model_d.c model_s.c sdlib.c assigns.c contact.c derivs.c gmc.c impact.c inits.c invert.c lcp_solver.c lmdif_c.c mathtools.c object.c output.c pipetools.c readmuscles.c readtools.c sdfor.c spring_based.c wrapping.c gcvspl.c user_def.lib forward.lib acpp.lib qhull.lib solid.lib wrap.lib I need to run the command: set_param([subsystemname,'/','S-Function'],'function name','forward','parameters','[0],[0],[0],[0],[0],[0],[1 0 0 0 20],[0]'); ...

Dear all I have C-code which I can compile with mex to a Matlab mex function (.dll) with a number of input and output arguments. My question is: what is the most straightforward way to build an S- function of this C-code to get a Simulink block with the same number of input and output ports as there where arguments in the original function? If I understand S-functions correctly, the resulting S-function should only have direct feedthrough, implementing the original function, and no continuous or discrete states. All comments and assistence are welcome Thanks Christophe ...

Hi All!! I have a C++ program that uses callback funtions which are the private members of class. The code uses an API wrtiiten in C which supplies callback-setting functions that require pointers to these functions... The funtions wherein these API's callback-setting functions are called, are public members of the same class of which the callbacks are the private member. Now the API functions are generating compile errors since they cannot "understand" the C++ function pointers. Consider the sample code: class classname { public : /* Constructor for the class...

Is the functionality provided by level 2 M structures at the same level as the one provided by C S functions? I mean if I can implement a Simulink block/function in using C-S functions, does it imply the same can be done with level 2 M-files? Your answers are most appreciated. --Ercan ...

Hello, beside the supported compilers for including c-code in MATLAB/Simulink, there exists a number of free compilers like GNU and WATCOM. Is it possible to use these compilers as well? Can anyone share his/her experience with such compliers? How about debuging? Can I use such a IDE also to debug MEX-files? I did not find very useful information on TMW home page. Thank you Michael Michael Salloker wrote: > > > Hello, > > beside the supported compilers for including c-code in > MATLAB/Simulink, there exists a number of free compilers like GNU > and > WATCOM. > ...

There are function for "Level-2 M-File S-Function" like the "Level-2 C-Mex S-Functions" ssGetTStart and ssGetSampleTime? Thanks for your help! Martin Bartl ssGetTStart <--> get_param(model_name, 'StartTime') ssGetSampleTime <--> block.SampleTime, where block is the runtime object that is available inside a level-2 M-file S-Function. "Martin Bartl" <MartinBartl@gmx.de> wrote in message news:oh27rss55xm7@legacy... > There are function for "Level-2 M-File S-Function" like the "Level-2 > C-Mex S-Functions" ssG...

Dear Community Members I'd like to convert my .m file function to a C/C++ callable dll function. How can I convert an m file function to a C/C++ callable dll function and How can I call and parse it inside a C/C++ function ? Yours Faithfully Cem DEMiRKIR ...

I am interfacing port to generate clock via parallel port. Is there any fucntion in C which can introduce a given delay . I remember in TURBO C++ 3.0, there was a function delay(milliseconds) in file 'DOS.H' Abhi <abhityagi85@gmail.com> wrote in message <29325805.1216546903931.JavaMail.jakarta@nitrogen.mathforum.org>... > I am interfacing port to generate clock via parallel port. Is there any fucntion in C which can introduce a given delay .. I remember in TURBO C++ 3.0, there was a function delay(milliseconds) in file 'DOS.H' IIRC, there is no standard C function, so each compiler/system has they own function. But try these: Sleep(), sleep(), ... For visual C, see here http://msdn.microsoft.com/en-us/library/ms686298.aspx Bruno ...

I have posted a question related to this yesterday, but I think I should try asking this question in stead: I have implemented mdlSetInputPortWidth, mdlSetOutputPortWidth, mdlSetInputPortDimensionInfo, and mdlSetOutputPortDimensionInfo in my s-function. The Simulink v. 5 manual on writing s-functions states for mdlSetInputPortWidth: "This method is called with the candidate width for a dynamically sized port." However, this does not happen in my s-function - they are never called. I have tried setting the port(s) in question to DYNAMIC_DIMENSION or by a DimsInfo_T struct specifying a...

Hi there, My question is about the difference between M-function and S-function. I didn't use S-function before. I always use M-function when I do some system simulation. I define the relationship between the inputs and outputs in an m file, and then link the M-function in my simulation to this m file. But what are the differences between M-function and S-function? Is there something that S-function can do while M-function cannot? Thanks. ...

Hi all, I was wondering if one of the experts out there can shed some light on the following question for me: I have a detailed numeric integration procedure coded in MATLAB that simulates induction motor behaviour. This is a fairly high level electric machine mathematical model that resolves a set of differential equations describing the machine behaviour in a time stepping iterative procedure (based on coding lines of solution procedure for each differential equation utilising Euler's rule and stepping these in a for loop for tiem progression). I would like to integrate this model into a Simulink controller model by converting it to a MATLAB function block. My question is, how can I synchronise the SIMULINK controller model with the Function block machine model's internal numeric integration - I would like the matlab function block to utilise numeric inputs calculated in "outer" simulink controller model, and use this to calculate (in a time step synchronised with the global simulink model) the neccessary outputs that will then be fed further into the simulink model as function block outputs. Can the function block be set up within the wider simulink model to inherit the time value at every step and use this in its internal calculations? Apologies for the confusing description - unfortunately its the best I can do at the moment! Regards, Sinisha ...

Hello I am an electronics engineer. Interested in using simulink. I am trying to do FFT inside an S function block (I am new to simulink, but have some experience with matlab). Somone please guide me on this Regards Aravind There is an FFT block in the Signal Processing Blockset is you have access to it. Otherwise you could use either a MATLAB Fcn block or an S-Function. Assuming the input signal is sample based (i.e. scalar at each time step), then the first thing you need to do is buffer the signal into an appropriate length vector before performing the fft. Within an S-funct...

Hi, Is it possilbe to write conventional C- functions, collect them as a library (perhaps a 'dll' in Windows) an then link them to an S-function (written in C) at runtime? For example, there is a simple special FIR filter, implemented as an standard C- function, which will be used by the 'mdlOutput' callback method of different S-functions, implementing diffrent Simulink blocks. Is there any way so that this function can be shared by all these S-functions? ...

Hi, I'd like to pass a C++ structure which has member functions from a mex function to workspace. For example, if function f() is the mex function, a = f(b,c); d = f(a,c); where the function f() returns a, C++ structure with member functions. Also, I'll send again the returned C++ structure, a, to the mex function f(). Thanks, Cheolhee Park wrote: > Hi, > I'd like to pass a C++ structure which has member functions from a > mex function to workspace. > > For example, if function f() is the mex function, > > a = f(b,c); > d = f(a,c); > > where th...

I have a system of C code, and a separate c-mex s-function .c file, which I would like to have my C system of code be able to access. The c-mex s-function has also been compiled into a .dll. Is there a way for me to allow my C code to call functions in the c-mex s-function .c file (or .dll)? From what I'm aware of, I believe that c-mex s-code is intended only to work in Matlab-based systems. Any advice about whether it will be possible to access the c-mex s-function code within my C code, and if so, how, is appreciated. Thanks! ...

I want to invoke DLL file in simulink, but the DLL file is not created by the c-compiler which matlab supports. How can I use my own c-compiler to build the c MEX s-function? thanks!!! ...

Dear All, I am trying to make a function to generate triangle wave in C code S-Functions. This will be used to make the carrier for PWM inverter simulation. does anyone have any idea about this, I've been searching but not result. Thanks anyone,, regards, Fred ...

I can find some answer from web, but I can't find their definitions in the C99 standard so far. Which page is it in? Thanks in advance. Hill Pang <pangbw@gmail.com> writes: > I can find some answer from web, but I can't find their definitions in > the C99 standard so far. > > Which page is it in? A function prototype is a *kind* of function declaration, one that specifies the types of the parameters. A non-prototype declaration has empty parentheses; it's also known as an old-style or K&R-style declaration, and it's obsolescent. The t...

Dear all, Is it possible to call a function in a Matlab mfile from a level 2 C-file S-function in Simulink? For example, in a mfile called Ratios.m I have the following codes. function [Ratio] = Ratios(A,B) Ratio = A/B; end And I want to call this function from a C-file S-function like this: .... static void mdlOutputs(SimStruct *S, int_T tid) { real_T X, Y, Z; ... Z = Ratios(X,Y); ... } When I compile the C-file S-function using mex in Matlab, an error message is displayed saying "undefined reference to '_Ratios' " Does anyone know how to resolve this ...

Resources last updated: 3/14/2016 1:53:12 AM