make all variables in function stored/global/accesible
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Adam
2016-12-19
编辑:Adam
2016-12-19
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 个评论
Steven Lord
2016-12-19
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!