Batch simulink problem

조회 수: 4 (최근 30일)
Amir Patel
Amir Patel 2011년 8월 6일
Hi all
I'm busy doing batch runs of my Simulink model using the command line 'sim' function in a Matlab script.
What I'm finding now is that after a random amount of runs (100 or more), the simulation crashes by saying one of the outputs of my S-functions is NAN or INF.
but if I type 'clear all' and run the exact same input parameters in model, it works. Very strange...
I've tried different integration solvers, to no avail. I've tried reducing step sizes.
I'm thinking maybe it has something with the way S-functions handle memory. Do S-functions keep their memory after a simulation run? Is there a way I can clear the memory allocated for my S-function, before I run the 'sim' command?
I'm really stumped on this one, so any ideas would be much appreciated.
Amir
  댓글 수: 2
Kaustubha Govind
Kaustubha Govind 2011년 8월 6일
Try using "clear mex" before each simulation and see if it helps? S-functions typically don't keep their memory between simulation runs, but the onus of clearing/destroying memory is on the S-function author. So you might want to check if your S-functions allocate global/static memory that is not being flushed.
Amir Patel
Amir Patel 2011년 8월 6일
Hi Kaustubha
The 'clear mex' before each simulation doesn't work either. I've tried that. I'm using P-Work vector in the S-functions themselves but I clear these in the mdlTerminate function. Is there a way to check that this memory is indeed being cleared?
Amir

댓글을 달려면 로그인하십시오.

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2011년 8월 6일
I am not sure. Memory could be the reason. To solve the problem, is it practical for you to put "clear all" or some types of clear memory command in your batch? That might be the easy solution. Or, if your repeating simulation run is iterative, it might be that the simulation is eventually unstable, i.e. one of the outputs of the S-funciton is indeed NaN or INF. By doing clear all, you won't be able to duplicate the problem manually.
When the problem happens, will you be able to check all your workspace variables to see if anything is abnormal? Will you be able to start the simulation manually, for a short period of time, to see what is going on with the simulation?
  댓글 수: 2
Amir Patel
Amir Patel 2011년 8월 6일
Hi Fangjun
I guess I could try and put a clear all, its just going to mean that I need to store the data somehow after sim run. I need all the data to do statistical analysis on.
Simulation run is just in a for loop. I don't think it is unstable because when the error occurs, I save all the input parameters in a .mat file, then execute 'clear all'. Then, if i load the input parameters again from the .mat file, the sim works.
I've also checked out the simulation output when the error occurs. The output scopes and they all seem to be fine at the time that the error occurs. Which is very strange!
Its almost as if all the s-functions output just go to NAN. I'm using P-Work vectors (but I clear these in the mdlTerminate function). Are the S-functions maybe running out of memory? I've tried the 'clear mex' command before each sim but that is not working either.
Fangjun Jiang
Fangjun Jiang 2011년 8월 6일
Yes. They way you save all the variables to .mat file and then recover is a smart move to debug the problem. I don't have much more advise except that maybe run "clear function", or "clear mex" and others (help clear to see all the other thing to clear) instead of "clar all". Just a way to nail down the problem if possible.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by