while loop: storing changing variables

10 ビュー (過去 30 日間)
D M
D M 2019 年 12 月 10 日
コメント済み: D M 2019 年 12 月 10 日
I am trying to write a program that runs user inputted variables through a while loop with a bunch of equations which outputs temperatures that will replace the inputted temperatures in the next iteration until the changing variables reach a certain tolerance. My question is, how can I make this loop more efficient, and how can I store the changing temperature variables more effectively?? So far, this is what I have:
i = 1;
T1 = %%initial temperature
while i < 100000
%%equations where T1 changes to a different T1
i = i + 1;
end
This loop is storing the changing temperatures correctly, I believe, but is not outputting the results I am looking for and I do not believe it is the most efficient way to run a while loop. If anyone has any advice it would be greatly appreciated, thank you.

回答 (1 件)

Bhaskar R
Bhaskar R 2019 年 12 月 10 日
i = 1;
T1 = %%initial temperature
tmp = zeros(1, 100000); % initialize temparature with zeros of length 100000
tmp(1) = T1; % assign T1 initial value to tmp variable
while i < 100000
%%equations where T1 changes to a different T1
tmp(i+1) = T1; % store T1 for each iteration
i = i + 1;
end
  1 件のコメント
D M
D M 2019 年 12 月 10 日
Thank you for the response. I tried this and it gives me the same output I get when I use the loop I have posted above.

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

カテゴリ

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