Hi Usha,
The rt_InitInfAndNaN function is a support routine inserted automatically when your model may involve special floating-point values, such as:NaN (Not a Number)Inf (Infinity). Its purpose is to initialize platform-specific representations of these values so they can be used reliably in the generated code.If you want to remove this function, you must ensure your model does not require non-finite values.You can do this by changing the following code generation settings:
- Go to Model Configuration Parameters Under Code Generation > System target file:Ensure it is set to 'ert.tlc'.
- Go to Code Generation > Interface tab:Set "Support non-finite numbers" to OFFSet "MAT-file logging" to OFF if not neededDisabling support for non-finite numbers tells Embedded Coder that your application will not use NaN, Inf, or -Inf, allowing it to omit rt_InitInfAndNaN from the generated code.
If this issue still persist, you need to follow the following troubleshooting steps that help you to know more about it.
Convert .mdl to .slx: This is the simplest and most effective solution.
- Open the .mdl model in R2024a.
- Save it as an .slx:
save_system('modelname', 'modelname_converted.slx')
- Use this .slx model for code generation. It should resolve the rt_InitInfAndNaN linking issue. .slx models trigger the latest build system compatibility and make Simulink regenerate and track required files more accurately.
Manually Include rt_nonfinite.c/.h:If you must want use a .mdl:
- Go to the generated code directory (e.g., model_ert_rtw/).
- Check if rt_nonfinite.c is there.
- If not follow steps 4 to 7:
- Manually add rt_nonfinite.c and rt_nonfinite.h to the custom code build.
- In Model Configuration Parameters: Go to Code Generation > Custom Code
- Add rt_nonfinite.c in Source files
- Add rt_nonfinite.h in Include files
You need to copy these files from another working code generation project or Simulink’s internal directories.
For more information regarding "rt_InitInfAndNaN", kindly refer to the following MATLAB documentation: