Why does Simulink ignore breakpoints in nested functions (r2020a)?

2 次查看(过去 30 天)
I have matlab functions in my simulink model. At the top level I can set breakpoints and from there I can continue, step in and out of nested functions and step row by row, but any breakpoints set in the nested functions are ignored. I had a similar problem in r2016b but this was solved by removing the slprj folder before i set the breakpoints. This doesn't help in r2020a. What should I do? It's impractical to step one line at a time to get to the lines of interest.
Thankful for any help on this.

回答(1 个)

Shubham
Shubham 2024-5-23
Hi David,
Debugging MATLAB functions within Simulink models can sometimes be tricky, especially when dealing with nested functions and the intricacies of how Simulink handles the MATLAB Function blocks. If you're experiencing issues with breakpoints not being hit in nested functions within your Simulink model in MATLAB R2020a, here are several steps and tips to troubleshoot and potentially resolve this issue:
1. Clear Persistent Variables and Reset MATLAB Path
Sometimes, stale state information or path issues can cause unexpected behavior in MATLAB and Simulink:
  • Use the command clear functions to clear persistent variables and reset the state of all loaded functions.
  • Use rehash toolboxcache to refresh the toolbox cache, which can sometimes resolve path-related issues.
  • Optionally, restart MATLAB to ensure a clean state.
2. Ensure Correct File and Function Visibility
  • Verify that the MATLAB files containing the nested functions are on the MATLAB path or in the current working directory. Use addpath('your_function_directory') to add directories to the MATLAB path if necessary.
  • Ensure there are no naming conflicts between your functions and other functions on the MATLAB path.
3. Check for Conditional Breakpoints or Disabled Breakpoints
  • Ensure that the breakpoints are not conditional breakpoints that have conditions which are not being met.
  • Verify that breakpoints are enabled (not accidentally disabled).
4. Use the MATLAB Debugger Commands for More Control
If the graphical interface doesn't behave as expected, consider using MATLAB's debugger commands for finer control:
  • Use dbstop in your script or command window to set breakpoints programmatically, for example, dbstop if error or dbstop in file.m at line_number.
  • Use dbstep and dbcont to step through and continue execution from the command window.
5. Update Simulink Model Settings
  • Check the simulation mode of your Simulink model. Make sure it's set to a mode that supports debugging (e.g., Normal mode instead of Accelerator or Rapid Accelerator).
  • In the Configuration Parameters dialog (Simulation > Model Configuration Parameters), under the Solver options, ensure that the model is not set to use fixed-step solvers with too large a step size, as this might skip over your breakpoints.
I hope this helps!

类别

Help CenterFile Exchange 中查找有关 Programmatic Model Editing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by