Placing breakpoint in subfunction

1 回表示 (過去 30 日間)
Terry
Terry 2013 年 11 月 12 日
コメント済み: Image Analyst 2013 年 11 月 12 日
I wrote a simple program in Matlab with a main function and a subfunction. However, when I run the program, the subfunction doesn't seem to get recognized. For example, when I place a breakpoint to the left of where I defined "B" and click Run, I don't get the k>> prompt in the command window.
The code is as follows:
function test
global A;
A = 5;
function test2
B = 6;

採用された回答

Image Analyst
Image Analyst 2013 年 11 月 12 日
For it to stop there, the first function, test, would have to call the second function test2(), which it currently does not do. It would if you did it like this:
function test
global A;
A = 5;
b_out = test2
function B = test2
B = 6;
  2 件のコメント
Terry
Terry 2013 年 11 月 12 日
Thanks for clearing that up. I have one more question. Why isn't the variable "A" recognized in the subfunction, even though I made it a global variable?
Image Analyst
Image Analyst 2013 年 11 月 12 日
global variables aren't automatically global. They're only global to those functions that declare them global inside the function. If it's not in the function, it won't see it.
function B = test2
global A; % Now test2 can see A.
B = 6;
Mark the question as answered if we're done. Thanks.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by