Detect Inf or Nan in Embedded Matlab Function block

조회 수: 3 (최근 30일)
Albert Yam
Albert Yam 2013년 2월 7일
Is there a way to detect an Inf or Nan being calculated inside an Embedded Matlab block. Simulink does not produce an error, but when we generated code, an exception was found. We are looking to protect against them. The problem can be reduced to the following.
[Constant block=0] --> [Embedded MATLAB Function] --> [Display]
Embedded MATLAB Function
function y = fcn(u)
test = 1/u;
if test > 0
y = 1;
else
y = 0;
end
"Configuration Parameters > Diagnostics > Data Validity > Inf or NaN block output", is just that, checking block output, and does not report this. (Which surprised me.)
Note: Simulink 6.6.1
Thanks.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 7일
Use isnan or isinf function
  댓글 수: 4
Albert Yam
Albert Yam 2013년 2월 8일
isnan and isinf require that the variable carry a value of inf or nan. On our generated code being run on our target platform, when that occurs there is already an exception. It never gets a chance to check for inf or nan.
So my protection, is an attempt to prevent the inf from occurring.
Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 8일
Maybe there is a way to disable such error message in configuration parameters. I will check it.

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

추가 답변 (0개)

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by