make all variables in function stored/global/accesible
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I have a function that has an error. It takes 10 minutes to reach the error in a loop. I dont know how to debug it unless I can make all the variables in that function stored at workspace. Is there a setting for this ? that file has over 200 variables
0 comentarios
Respuestas (2)
Adam
el 19 de Dic. de 2016
Editada: Adam
el 19 de Dic. de 2016
Use
dbstop if error
to stop the code at the point in the function where the error is. I can't imagine why you would ever want 200 variables in a single function, but that is another matter entirely.
If you wish you can dump them all to a .mat file using
save( filename )
at some point, including at the point the above will stop in your code.
The whole point of a function though (well, one of the key points, at least) is to encapsulate the variables within a sealed workspace of the function and not contaminate the workspace that called the function so debugging with stop on errors is the simplest way.
0 comentarios
Steven Lord
el 19 de Dic. de 2016
MATLAB has a debugging system that you can use to stop on a particular line in a function or when an error occurs. This will stop as the function executes, so you have access to all the variables that are present in the workspace and can use them to diagnose the cause of the problem.
0 comentarios
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!