Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: S-Function MEX file help
Replies: 2   Last Post: Jun 30, 1996 11:19 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Mark David Anderson

Posts: 4
Registered: 12/7/04
S-Function MEX file help
Posted: Jun 27, 1996 2:51 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I am sorry for asking so many questions (it seems) as of late, but here's
another...

I am trying to convert a .m s-function to a .mex file to speed up
my simulation as it is taking quite a long time since the addition of
the .m file. I am having two main problems though.

(I should note that I have written .mex files before, but none as complex
as what I'm trying to do).

1) The file should perform some actions at only specified times,
sampling times, if you will. I have had very little luck with the
"ssIsSampleHitEvent(S, 0, tid)" type of construct to test for a smple
hit. I have initialized the sample times at the beginning (I have two
sample times) and have also set their offsets (they each have a non-zero
offset), as such:

ssSetSampleTimeEvent(S, 0, 720.0);
ssSetOffsetTimeEvent(S, 0, mxGetPr(CLOSING)[0]);

ssSetSampleTimeEvent(S, 1, 720.0);
ssSetOffsetTimeEvent(S, 1, 360.0);

If I put the actual value for CLOSING in the set statement it makes no
difference. What this should do, in my attempt, is have two sample times, both
of every 720 "seconds", one with an offset of, say, 240 seconds, the other,
360 seconds. It does not work. The if statements (e.g.
if (ssIsSampleHitEvent(S, 0, tid)) ) are never true and so my code does
not get executed.

I have tried to just use the time directly, using a comparison of an integer
time with a float time, and if they are equal to within 1e-6 seconds,
execute the code, but it does not always work, depending on the current
step size, it seems (I have used this approach, outlined in an example
file, successfully before, but with the same kind of flakiness). I was
hoping the ssIsSampleHit would get rid of the flakiness.

2) I was told that there is no equivalent .MEX funtion to the .m-function
"set_param", and that I'd have to use the "mexEvalString" and
"mxCreateString" functions to do it. Unfortunately, I have no idea how to
do this, so if anyone could be of any assistance, I would greatly appreciate
it. Basically, I am just trying to set the parameters of a 2-D lookup table
on the fly...

Thanks in advance for any suggestions or help anyone can offer!

Mark Anderson





Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.