Variables created within function are cleared from workspace after reaching error
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 13 de Mayo de 2021
Comentada: Steven Lord
el 13 de Oct. de 2022
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?
Respuesta aceptada
MathWorks Support Team
el 13 de Mayo de 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 comentario
Steven Lord
el 13 de Oct. de 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.)
Más respuestas (0)
Ver también
Categorías
Más información sobre Whos en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!