Variables created within function are cleared from workspace after reaching error

5 Ansichten (letzte 30 Tage)
I'm running a MATLAB R2020b script that creates several variables within a function. Somewhere in the function, I am receiving an error, which causes these variables created before the error to disappear from my workspace window. This is making it hard to debug my code. How can I make sure these variables are kept in the workspace even after the error?

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 13 Mai 2021
Code erroring within a function will not store the function variables in the base workspace, so this is intended behavior. In order to see the values for the variables inside the function before the error, place breakpoints inside the function. Breakpoints will pause the execution of the program once it reaches the specified line, allowing you to observe the workspace variables at that point for debugging purposes.
For more information on setting breakpoints in MATLAB, please read the following documentation:
  1 Kommentar
Steven Lord
Steven Lord am 13 Okt. 2022
If you set a standard breakpoint on a line inside the loop that is correct. In that case I would suggest setting an "error breakpoint" (see the Error Breakpoints section on the documentation page to which the MathWorks Support Team linked) which will cause MATLAB to enter debug mode exactly when the error occurs (in the case of a loop, it would only break on the line and in the iteration where MATLAB throws the error.)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by