How to Access All Variables of a Function?

조회 수: 21 (최근 30일)
Rightia Rollmann
Rightia Rollmann 2017년 3월 16일
댓글: Steven Lord 2017년 3월 16일
Imagine I have several functions in an M File and want to see ALL variables of one of these functions when it is executed. How?
I use
assignin('base', 'var', val)
to see inside a function, but it only show one of variables of a function, but I want to see ALL variables of its. My main purpose to do so is to check whether all variables are working and they have a correct structure and value

채택된 답변

Adam
Adam 2017년 3월 16일
편집: Adam 2017년 3월 16일
Use the debugger. There are keyboard shortcuts and programmatic triggers, but I can never remember most of them. There's a Breakpoints menu in the editor and you can also add breakpoints by clicking in the left margin of an open file on the line you want. Then the code will stop there and you can view everything on command line.
There's no need to start trying to chuck all the variables into the base workspace, it is far better to see them in context as they are evolving, and you can step through each line of the code too with the debugger,
  댓글 수: 3
John D'Errico
John D'Errico 2017년 3월 16일
Anyway, all you would see is the final value of those variables if you dumped them into the base workspace. USE THE DEBUGGER. That is exactly why it is there. It is easy to use. Does not require any change to the code. Allows you to see what is happening at any or every point in the function.
Steven Lord
Steven Lord 2017년 3월 16일
In case you're not sure how to use the debugger, there's a page in the documentation that shows the list of functions that allow you to programmatically debug your code. If you prefer to use a debugging user interface instead, the three Topics on that page walk through an example of debugging a function, discuss the various types of breakpoints, and show several tools and techniques for viewing variable values when a function is stopped in the debugger.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by