フィルターのクリア

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 Center および File ExchangeDebugging and Analysis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by