Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



SFunction MEX file help
Posted:
Jun 27, 1996 2:51 PM


I am sorry for asking so many questions (it seems) as of late, but here's another...
I am trying to convert a .m sfunction 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 nonzero 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 1e6 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 .mfunction "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 2D lookup table on the fly...
Thanks in advance for any suggestions or help anyone can offer!
Mark Anderson



