フィルターのクリア

How to make available initialization variables in workspace

4 ビュー (過去 30 日間)
Marco
Marco 2012 年 9 月 27 日
Hello,
when a script, after declaring variables, I create a loop (eg. while) they are available in the workspace at the end of the loop
Is there a way to make them available since the execution of the script?
  2 件のコメント
Matt Kindig
Matt Kindig 2012 年 9 月 27 日
I think I understand your question. You're wondering why the workspace variables are not displayed in the Workspace during the loop execution. The reason is that the Workspace is not refreshed until the script is finished completion. Refreshing the Workspace during script/function execution is a feature that I've also wished for!
Marco
Marco 2012 年 9 月 27 日
I know that if in a while loop I need to return a value I can use "return" command...maybe I have to create/initialize variable before run (???)

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

回答 (2 件)

Kevin Claytor
Kevin Claytor 2012 年 9 月 27 日
You probably want to set a debug point somewhere in the while loop - either use the debug command or click the tick mark next to the line number. The program will pause at that point and give access to all variables in the current workspace. Here's a video to get you started.
  1 件のコメント
Marco
Marco 2012 年 9 月 27 日
I guess a breakpoint may be my solution, but... is there a way to automate the Continue (F5) button inserting it in the code with the condition?

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


Image Analyst
Image Analyst 2012 年 9 月 27 日
If you have a script, the variables will remain in the base workspace:
File test.m:
a = 42;
b = 'These will hang around';
If you have a function, then will vanish when your m-file finishes:
File test.m:
function test()
a=42;
b = 'These will NOT hang around';
Note that the "function" line in the second file turns it from a script into a function, and that means that the variables are local to that function and will vanish when the function exits. If it's a script, like in the first case, the variables will still be there for you to inspect in the base workspace.
Understand?
  11 件のコメント
Image Analyst
Image Analyst 2012 年 9 月 29 日
編集済み: Image Analyst 2012 年 9 月 29 日
The workspace should get updated every iteration. workspace simply shows the panel - it doesn't force the panel to update. You definitely don't need it inside your loop! If you're in a really intensive tight loop and you find that the workspace panel does not immediately show the changing values, you can try to put a "drawnow" in your loop to try to force the user interface to update, or else display the values in the command window or a GUI like I said earlier. If you use a custom GUI, and it's in a tight loop, then you're going to have to use "drawnow" in the loop to get the GUI to update on every iteration. Otherwise, message are just getting sent there but they're just queued up and don't get acted upon until Windows gets around to it (that's how multitasking operating systems work).
Marco
Marco 2012 年 9 月 29 日
Ok, I understand, thanks!

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by