How to save output from equation in for loop into an array

12 ビュー (過去 30 日間)
Kevin Burg
Kevin Burg 2021 年 5 月 29 日
I currently am calculating the values for an equation over a range of values. The output is only saving the last calculated in the value of the foor loop. How do I create an array so all the values are stored? Thank you for the help
% Range from 0.0 m to 4.00 m using 0.01 m increment
for i = 0.0:0.01:4.00
% Formula for enthalpy from entrance to exit
x_out = x_in + ((1/m)*(pi*Q_flux*D*i));
end

採用された回答

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 5 月 29 日
% Range from 0.0 m to 4.00 m using 0.01 m increment
t=0.0:0.01:4.00;
for ii = 1:numel(t)
% Formula for enthalpy from entrance to exit
x_out(ii) = x_in + ((1/m)*(pi*Q_flux*D*t(ii)));
end
  1 件のコメント
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 5 月 29 日
Note that this can be also solved without a loop using vectorization.
x_out = x_in + ((1/m)*(pi*Q_flux*D*(0.0:0.01:4.00)));

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by