f



C-mex S-function: nested functions of different typecast

I am trying to create an C-mex S-function with an additional nested function. However, I am having a hard time with all the different pointers and typecasts. Help would be very much appreciated :).

Question: Does anyone notice strange type conversions in the code below?

The compiler does not complain, but Simulink crashes with a fatal error.

static void mdlOutputs(SimStruct *S, int_T tid)
{
void evaluatespline_1p(double *, double *, const double *, const double *, double *, double *);
....
    const real_T* Cx = ssGetInputPortRealSignal(S,0);
    const real_T *Cy = ssGetInputPortRealSignal(S,1);
.....
    real_T       *sr0_norm  = ssGetOutputPortSignal(S,1);
    real_T       *Srf       = ssGetOutputPortSignal(S,3);
....
    double teta[4];
    double dteta[4];
.....
     evaluatespline_1p(sr0_norm, Srf, Cx, Cy, teta, dteta);
.....
void evaluatespline_1p(sr,Srf,Cx,Cy,teta,dteta)
double *sr[4];
double *Srf;
double *Cx[NR_C];
double *Cy[NR_C];
double *teta[4];
double *dteta[4];
{
a lot of stuff to calculate the output values for teta and dteta:
    *teta[k]=atan(dY/dX);
    *dteta[k]=((dX*ddY-dY*ddX)/(dX*dX+dY*dY))*(NR_C-3)/(*Srf);
}
0
m.w.disse (11)
9/3/2012 4:08:08 PM
comp.soft-sys.matlab 211266 articles. 25 followers. lunamoonmoon (257) is leader. Post Follow

0 Replies
817 Views

Similar Articles

[PageSpeed] 33

Reply:

Similar Artilces:

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

Segmentation violation when calling a C-MEX function from a C-MEX S-Function using mexCallMATLAB
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...

Call Matlab functions from mex (matlab function's input is string)
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...

How to get global-variable functionality in c-mex s-function?
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...

difference b/w S-function and Embedded matlab function
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...

Error while obtaining sizes from MEX S-function 'forward' in block 'dummy/Dynamic_Model/S-Function'. MATLAB error message:.
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]'); ...

C-file S function from Matlab mex
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 ...

Calling C++ functions in C function through function pointers
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...

level 2 M-S function == C S function ??
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 ...

Compiler for C-MEX/C s-Functions
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. > ...

Level-2 M-File S-Function like Level 2 C-MEX Functions ssGetTStart and ssGetSampleTime
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...

How can I convert a matlab function to C/C++ callable dll function ?
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 ...

function in matlab to delay() function in C
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 ...

mdl- functions i C s-functions
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...

difference between M-function and S-function
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. ...

MATLAB Function Block or S Function
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 ...

S Functions or Matlab function blocks
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...

Simulink "S-function"s dynamic linking with ordinary C functions?
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? ...

C++ structure with member functions in mex function
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...

Is it possible to make C-mex s-function code C-compatible?
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! ...

How to use others c-compiler to build the c MEX s-function? #2
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!!! ...

triangle wave function in C Code-S Functions
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 ...

What's the difference between function declaration and function prototype?
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...

C-file S-function calling function in mfile
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 ...

Web resources about - C-mex S-function: nested functions of different typecast - comp.soft-sys.matlab

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