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!