How to inspect local variables of a function

16 ビュー (過去 30 日間)
Moshe
Moshe 2012 年 9 月 21 日
I'd like to be able to view the local variables generated during the run of a function. One way is to load them to my workspace by saving them to a file, but that could become cumbersome as the number of temporary files proliferate as I experiment with running the function with different parameters. Is there another way?
  2 件のコメント
José-Luis
José-Luis 2012 年 9 月 21 日
Well, you could just return the variables you are interested in... Or am I missing something?
Moshe
Moshe 2012 年 9 月 21 日
I want to debug the code, so I'd like to quickly inspect all the variables, and how they change with the parameters, to see what is going on. I am looking for a minimal solution to do so, without creating loads of temporary objects.

サインインしてコメントする。

採用された回答

José-Luis
José-Luis 2012 年 9 月 21 日
Use breakpoints either in your script and/or in your function.
  1 件のコメント
Moshe
Moshe 2012 年 9 月 21 日
This seems like the right approach, still learning the basics...Thanks!

サインインしてコメントする。

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 9 月 21 日
編集済み: Azzi Abdelmalek 2012 年 9 月 21 日
declare them global in both your function and matlab command
global var1 var2 var3
  3 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 9 月 21 日
I think he just want to debug his code
Sean de Wolski
Sean de Wolski 2012 年 9 月 21 日
So don't use globals! That's a really bad idea as it will exacerbate whatever problem you're having!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeVariables についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by