How to have variables displayed in workspace after every while loop iteration?

16 ビュー (過去 30 日間)
Nancy
Nancy 2014 年 11 月 12 日
コメント済み: Star Strider 2014 年 11 月 13 日
Hi all,
I have a while loop in which my variables are only stored in the workspace after the entire loop is completed. Is there any way that I can store the variable in the workspace after each iteration of the loop, because I need to use these values while the loop is still running. Thank you!
  8 件のコメント
per isakson
per isakson 2014 年 11 月 12 日
  • YES, the variable can be used!
  • Regarding the words, in this case I think displayed in the workspace window is better than stored in the workspace
per isakson
per isakson 2014 年 11 月 12 日
Regarding "additional questions" &nbsp Your chance to get a good answer increases if you make it a separate question with an appropriate subject line.
out(end+1) = str2num(value); &nbsp might work.

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

採用された回答

Star Strider
Star Strider 2014 年 11 月 12 日
The easiest way (without seeing your code) is to initialise a counter before the loop, increment it within the loop, and subscript the variables calculated in the loop:
k1 = 1;
while some_condition
a(k1) = some_expression;
b(k1) = some_other_expression + a(k1);
k1 = k1+1;
end
Here, ‘a’ and ‘b’ will be available as vectors at the end of the loop, and available to each other within the loop. That’s as specific as I can get.
  8 件のコメント
Nancy
Nancy 2014 年 11 月 13 日
Thank you!!! Appreciate it!
Star Strider
Star Strider 2014 年 11 月 13 日
My pleasure!

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

その他の回答 (1 件)

Andrew Reibold
Andrew Reibold 2014 年 11 月 12 日
編集済み: Andrew Reibold 2014 年 11 月 12 日
Not sure if you are having issues with the worksplace, or if you are actually trying to say you are having trouble displaying values to the screen while running the program
Instead of using
out(length(out) + 1) = str2num(value)
Can you use...?
out(i) = str2num(value)
Then, can you use...?
disp(out(i))
Or if you want to keep track of which iteration you are on also,
disp(['Iteration ',i,'- Out value of ',out(i)])
  1 件のコメント
Nancy
Nancy 2014 年 11 月 12 日
Thank you for your help, but my question is that out is not being displayed in the workspace as the loop is running because I want to be able to access the variable while the loop is still running in another code that will be running in parallel. Also if you dont mind can you please take a look at my other question above^. Thank you!

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

カテゴリ

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