Tracking the value of a variable in Debug Mode

I have several variables that I want to track the values of throughout my function. I only seem to be able to track the value when I place a break-point at a point of interest. Is there some sort of "tag" function in which I can tell Matlab to continually track the value of a variable?

3 件のコメント

Stephen23
Stephen23 2015 年 7 月 7 日
編集済み: Stephen23 2015 年 7 月 7 日
What exactly does "...to continually track the value of..." really mean?
There are two main options for finding what value a variable has:
  1. print it (to screen).
  2. use the debugging tools.
It does not make much sense to track variable values in real time, as most functions and operations will be too fast for a human to follow them. So presumably "tracking" means during debugging... in which case these steps will lets you follow any variable that you wish to:
  • set a break-point on the line after where the variable first appears.
  • run the function.
  • view the variable in the workspace, or open it in the variable viewer.
  • step through the function using the F10 button.
Debugging gives access to that local workspace, and lets you observe the value by using the standard variable viewing tools, so you can track it easily. Depending on what you mean by "tracking".
DeeWBee
DeeWBee 2015 年 7 月 7 日
If I variable "X", I want the value of X to be displayed somewhere at any given moment.
Image Analyst
Image Analyst 2015 年 7 月 7 日
If the value is a pixel value (a gray level or RGB value), then you can use impixelinfo() where it will update a status label with the image's color as you mouse around the image. Otherwise for a general variable, then do as my answer below mentioned.

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

 採用された回答

Image Analyst
Image Analyst 2015 年 7 月 7 日

2 投票

You can list the variable's name by itself on it's own line in your source code, with no semicolon after it. When execution hits that line of code, it will spew the value of the variable out to the command window. No breakpoint needed.

1 件のコメント

DeeWBee
DeeWBee 2015 年 7 月 7 日
Groovy perfect! Thanks.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by