Error Handling WITHOUT using try-catch statments
이전 댓글 표시
Hello,
I am trying to convert some of my MATLAB functions in to a form that is compatible with Embedded MATLAB.
I have a try-catch statement that attempts to run a simulation (try) and if the simulation fails (catch) returns a zero. By doing this the function can deal with failed simulations without crashing.
Unfortunately embedded MATLAB does not allow try-catch statements.
Does anyone know of a way I can handles this error without using try-catch?
Thanks.
댓글 수: 2
Kaustubha Govind
2011년 5월 19일
Do you mean that you are simulating another model from within an Embedded MATLAB Block in a Simulink model? Is there a reason you chose to use the Embedded MATLAB block as opposed to the Model reference block?
One potential solution would be to perform the try-catch in a separate MATLAB function, which is called from the Embedded MATLAB block after declaring it using eml.extrinsic (coder.extrinsic starting in R2011a).
Will
2011년 5월 19일
답변 (2개)
Arnaud Miege
2011년 5월 19일
0 개 추천
I wouldn't recommend trying to run a Simulink model within an Embedded MATLAB Function, which itself resides in another Simulink model. It means that at each time step of the "caller" model, you're running a simulation of the "called" model. This is extremely inefficient as you could potentially have thousands of time steps. As suggested, a better solution would be to use a Model Reference to include the "called" model by reference into the "caller" model.
댓글 수: 5
Will
2011년 5월 19일
Arnaud Miege
2011년 5월 19일
That won't work. You can't generate C code from the sim command. These are the functions supported for code generation:
http://www.mathworks.com/help/releases/R2011a/toolbox/eml/ug/bq1h2z7-11.html
Using Simulink Coder, you can generate C code from the model itself.
Will
2011년 5월 20일
Arnaud Miege
2011년 5월 20일
I'm not sure, sorry. One thing is with the generated C code, you only work one time step at a time, there's no notion of simulation time, so I'm not sure it makes sense to think of a simulation having failed.
Will
2011년 5월 23일
Walter Roberson
2011년 5월 19일
0 개 추천
The only error control mechanism supported by C is signals. I don't know if error conditions produce signals; I do not recall having heard anyone refer to that as a possibility.
카테고리
도움말 센터 및 File Exchange에서 Simulink Environment Customization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!