f



difference between c mex and m -file for s function

hello,
  I have a s-function that composed by the m-file method, but the
excuation time is too long for the real-time simulation. Thus I
converted the s-function from m-file to c-mex method.
  Then,I use these two methods(m&c) to construct s-functions
respectively at a simulink model, and these two s-functions will
generate two curves,I try to make this two curves match completely to
confirm if the c-mex code is correct, but this two simulation
curves(m&c) are identical nearly, not match completely.The solver is
ode2 and sample time is about 0.05ms, could you give me so idea or
suggest?

thanks a lot....

Eric
0
5/26/2006 5:19:51 AM
comp.soft-sys.matlab 211266 articles. 25 followers. lunamoonmoon (257) is leader. Post Follow

0 Replies
659 Views

Similar Articles

[PageSpeed] 6

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

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); } ...

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

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]'); ...

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

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

C/C++ in matlab and matlab in C/C++ ?
Is it possible to read C/C++ code in matlab and the other way around too? Hi, as long as C or C++ are written in text files you can edit them in the matlab editor. To see the special character of C or C++ coding language, in the editor go to menus: file>preferences>Edito/Debugger>language and on popup "Language" select "C/C++". This does not allow you to run the C/C++ code, just to view it i nicer way... regards, chris saneman <asdfsdf@asd.com> wrote in message <frl846 $f8i$2@news.net.uni-c.dk>... > Is it possible to read C/C...

How To Use Hardware API based on DLL's In a C MEX S-Function Using
Im trying to create an S-function which will read/capture data from hardware in a system, which will then be used in a Simulink model. The hardware drivers and hardware API makes use of ".dll" files. Is it possible to include/use these .dll files in a Simulink s-function so that the functions within can be used in the C MEX S-function?? If so will you be able to give an example or directions? All attempts so far has led to syntax errors or the following: error LNK2019: unresolved external symbol __imp__fntest_dll referenced in function _doubleIt test.mexw32 : fatal error LNK1120...

Need Help on Matlab C code S function error with VS 2005 C++ compiler
I am using a MS Vista Utimate OS on a 64 bit PC with MATLAB R2007b. I have MS Visual Studio 2005 Pro installed in the same PC. When I compile a C code S function, I got the following error with Microsoft Visual C++ compiler (see mex -setup output list below). By the way, the same code compiled with icc.exe on a 32 bit PC with WinXP OS and worked fine. Please help me with some insight into this compilation problem. mex('s_xmp6L2.c') s_xmp6L2.c s_xmp6L2.c(39) : warning C4013: 'mdlCheckParameters' undefined; assuming extern returning int s_xmp6L2.c(55) : error C2371: '...

mexCallMatlab with C MEX S-Function
Hello, I am trying to work mostly with Simulink but I have a problem with the fft block. It works only with radix2 dimensions and I need a 160 point fft. Zero padding is not an option, that's what my Prof. said. So I turned my attention to the mxCallMatlab, but I am quite confused about using this function. That's because I have little experience with C programming. Here is how the situation looks like: I have a C MEX S-function where I address my input with: InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0); and then the output something like this: *y++ = *uPtrs[i] &l...

Run C s-function in Matlab
Due to lazyness (to avoid reprogramming), I want to call my C s-function (the output part) from a matlab script. However, it seems the straigtforward (?) way of doing this fails: y = mysfun(0,x,u,3); gives me ??? Invalid flag passed to MEX level2 S-function "mysfun" Any hints or thoughts? L. ...

C MEX S-Function Problem
How can I include a C-file in a C MES file ?? How can I include the S-function into a model ?? There's an s-function block in the Simulink library. Add this to the model and change the s-function name parameter to correspond to your mex-file. Mex-file is actually a dll, which has certain structure. This structure is documented in the Simulink help files (see Matlab help->Simulink->Writing S-functions). You can create a mex-file from a c-file that has the correct function structure with the command 'mex filename.c'. If you want to use functions from other c-files in your c-mex file, you can add them to the mex-file by commanding Matlab: 'mex filename.c helpfile.c' etc. -juha ���� wrote: > > > How can I include a C-file in a C MES file ?? > How can I include the S-function into a model ?? > > > Thx for replying but I've got some problems when building the realtime model (.mdl) MATLAB always shows the following error message: Error executing build command: Error using ==> make_wc Error using ==> make_rtw Error using ==> rtw_c Error(s) encountered while building model "temp" and ### Creating library: rtwlib.lib temp.c rt_code.c rt_sim.c ode1.c LINK : fatal error LNK1181: cannot open input file "testmex.obj" NMAKE : fatal error U1077: '"C:\PROGRA~1\MICROS~1\VC98\bin\link.exe"' : return code '0x49d' Stop. The problem is the building process always complains that t...

what's the difference between a^M and a.^M, where M is a matrix?
I know how a.^M operates, but don't know what a^M means. On 26/01/11 12:03 PM, Ha wrote: > > I know how a.^M operates, but don't know what a^M means. a^2 is a*a which is linear algebraic matrix multiplication "Think blue, count two." <roberson@hushmail.com> wrote in message <KGZ%o.53285$T87.16755@newsfe01.iad>... > On 26/01/11 12:03 PM, Ha wrote: > > > > I know how a.^M operates, but don't know what a^M means. > > a^2 is a*a which is linear algebraic matrix multiplication M is a NxN matrix, rather than a scalar. ...

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

Syntax problem with C-mex s-function
I'm creating a c-mex s-function that calls functions from an existing library. However, due to the way that the code is set up, I need to perform an extra step when calling these functions, by creating a pointer to each function. I have one function correctly set up -- the code compiles without problems, and the generated mex file can be successfully used. However, I'm trying to duplicate this working, template setup for several other functions, and am now getting a puzzling compile error. Details are below: My correctly functioning code is: typedef bool (*cwPointer)(int arg1, int ...

C-Mex S-Function Reading from Workspace
Hi all, I have a tab-delimited file that I'm reading into the Workspace using an M-script. I would like to pass that matrix to a C-Mex S-Function. Please help. Thanks. SK ...

C-Mex level 2 S-function
Using the template I wrote an S-function in C, created a new mdl file, added an S-function block, assigned the function name to the Function Block Parameters. Then I created a subsystem box to attach the function code file as shown in some of the simulink examples. But I do not know how to link the file. Is there any demo showing this step? or can you describe how. Thanks Ahmad ...

Problem with compiling c-mex s-function
I had previously been able to compile my C-mex s-function code into a mex function, using the command >> mex controller_CMEXsfcn.c LibraryFile.lib However, my system setup has changed (new operating system [had been XP, now 32-bit Windows 7], etc.). Now, when I execute the same command above, I now get the error message: ----------------------------- Open Watcom C/C++ CL Clone for 386 Version 1.3 Portions Copyright (c) 1995-2002 Sybase, Inc. All Rights Reserved. Source code is available under the Sybase Open Watcom Public License. See http://www.openwatcom.org/ for details. Warning: ...

create object in C++ mex S-function
When I create object of a class by calling myClass* p_myClass = new myClass(); outside all the S-function method, it will work for the first run. When I run the model again, it outputs a really small number, which doesn't seem to work properly. When I put create the object and store the pointer using PWork vector inside mdlStart, it works. What is the difference? Below is my simple code to test this. #define S_FUNCTION_LEVEL 2 #define S_FUNCTION_NAME test_1 #include "simstruc.h" #include "myClass.h" #define NumInput 0 #define NumOutput 1 // this does not work properly myClass* p_myClass = new myClass(); static void mdlInitializeSizes(SimStruct *S){ int PortIndex; ssSetNumSFcnParams(S, 0); /* Number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { /* Return if number of expected != number of actual parameters */ return; } ssSetNumContStates(S, 0); ssSetNumDiscStates(S, 0); // InputPort if (!ssSetNumInputPorts(S, NumInput)) return; //no input // OutputPort if (!ssSetNumOutputPorts(S, NumOutput)) return; for (PortIndex=0; PortIndex<NumOutput; PortIndex++){ ssSetOutputPortWidth(S, PortIndex, 1); } ssSetNumSampleTimes(S, 1); ssSetNumPWork( S, 1); ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE); ssSetOptions(S, 0); } static void mdlInitializeSampleTimes(SimStruct *S...

Data transfer between C-Mex S-functions ...
Hi, Firstly I'd like to store data resulting from S-function calculations S-function A is performing calculations which results are stored in : 1/ Matlab WorkSpace 2/ Model WorkSpace 3/ S-function UserData Question 1 : Could you describe (shortly) the way to do those 3 operations ? Secondly I'd like to read previously stored data (in another S-function) S-function B needs those data to perfom its calculations. Question 2 : How could B access data previously stored by A (in the 3 cases) ? Question 3 : What's the most efficient way to perform this Write/Read operation (1, 2 or ...

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

Calculating remainder (modulus) in C Mex S Function
I'm having problem in converting data type within C Mex S function. I would like to calculate the modulus of a real_T data type. if I calculate remainder using C language format i.e., (input%5) in C Mex S function, then I get errors in compiling mex function. Can anyone of you help me how to calculate the remainder operator in the C-mex S Function? My code looks like this real_T data; real_T Sample_Length = 120; int_T counter; counter = 0; if (data%Sample_Length==0) { counter= counter +1; } Or is there any other way I can realize this modulus operator? Saif ...

matlab like c's getchar function
In c-language, the getchar function can get standinput. In MATLAB, the function call which name? akira32 wrote: > > > In c-language, the getchar function can get standinput. > In MATLAB, the function call which name? Look for getcharkey on the matlab file exchange. <http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=7465> It may do what you want. Jos Jos wrote: <SNIP ... getcharkey ... AD comes early this year. I meant GETKEY Jos <x@y.z> wrote in message <ef5b00e.1@webcrossing.raydaftYaTP>... > Jos wrote: > <SNIP ... ...

Passing Mask Parameter to C-mex S Function
Hallo, i have several C-mex S-Functions to which i would like to make ONE mask Block so that i cann enter the name and the parameters of the S-function on the mask dialogbox. So How can i pass the name and the parameters of the s-function from the mask into the s-function block? Thanks in advance!! Ali ...

Calling a MATLAB function from within a mex C routine
Hey, I'm pretty new to mex programming, and have query. I have a mex implementation of a MATLAB function which has some minimization routines (fzero, fminbnd) in it. As I would rather not write these routines from scratch in C, I wish to call the MATLAB minimization functions from within the C subroutine of the mex function. Is it possilbe to do this, and how would I go about doing it ? Thanks a bunch, John. Johnny wrote: > Hey, > > I'm pretty new to mex programming, and have query. I have a mex > implementation of a MATLAB function which has some minimizat...

Web resources about - difference between c mex and m -file for s function - comp.soft-sys.matlab

Difference - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

3Q EARNINGS: Mark Zuckerberg on the Differences Between Messenger and WhatsApp
When Facebook announced its intent to acquire cross-platform messaging application WhatsApp in February, questions surfaced on whether WhatsApp ...

Facebook Tips: What’s the Difference between Top News and Most Recent?
The following is part of our series, Facebook Tips, which answers some of the most commonly asked questions about using Facebook. While we hope ...

No evidence Ritalin makes a difference long term for ADHD kids
... to struggle academically and mentally as they get older, regardless of whether they're on medication. Drugs such as Ritalin make no difference ...

The X factor: Who's ready to make a difference for your club?
We take a look at a player from each club who used the NAB Challenge to show they could give their team&nbsp;something different in 2016.

Galaxy S7 Isocell vs Sony camera sensor: what’s the difference?
... have every right to believe all Samsung Galaxy S7 handsets are created equal, but such is not the case. And we are not only talking about differences ...

The marginal importance of marginal ideological differences on the Supreme Court
I am not getting the argument that Obama’s choice of a moderate justice is a massive concession even if he can be confirmed before the lame duck ...

What are the differences between AR and VR?
Now that HTC Vive has become available, we seem to have moved past virtual reality that gives you motion sickness and we can really start to ...

Not a dime's worth of difference?
Not a dime's worth of difference? by digby There are many differences between the parties but this one may be the most important: [B]illionaire ...

The Democratic Party Brand Is So Fouled By Blue Dogs And New Dems That Voters Don't Know The Difference ...
... One crucial challenge along the way may be to get voters to appreciate that on these issues, there are stark, deeply consequential differences ...

Resources last updated: 3/20/2016 5:48:30 PM