Batch simulink problem

12 ビュー (過去 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 Center および File ExchangeSimulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by