make all variables in function stored/global/accesible

조회 수: 1 (최근 30일)
RuiQi
RuiQi 2016년 12월 19일
답변: Steven Lord 2016년 12월 19일
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

답변 (2개)

Adam
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.

Steven Lord
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.

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by