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 CenterFile Exchange에서 Variables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by