For loop with decimal number matrix

16 ビュー (過去 30 日間)
Abdulaziz Gheit
Abdulaziz Gheit 2019 年 3 月 16 日
コメント済み: Star Strider 2019 年 3 月 16 日
Hi,
Any help with this for loop. I write a for loop and i tell it to increment by a small value, let's say 0.01. This loop is simple example of my issue. In my code I need to create big zeros soultion matrix to save my results into it.
if my loop increment is decimal number, how should I write the soultion matrix?
Thanks
NTUmax=10;
tt=100;
Soulution=zeros(tt,NTUmax);
for i=1:NTUmax %% Incrementing value should be e.g equal 0.1
NTU=(i);
dtempdt=NTU*2;
Soulution(:,i)=dtempdt;
end
  2 件のコメント
madhan ravi
madhan ravi 2019 年 3 月 16 日
Why do you need a loop? , the answer is simpler than a loop.
Abdulaziz Gheit
Abdulaziz Gheit 2019 年 3 月 16 日
Hi madhan ravi,
This is just an example. I have a complicated numerical code and it's not as simple as this example.
Thank you very much for your attention

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

採用された回答

Star Strider
Star Strider 2019 年 3 月 16 日
I am not certain what you want to do.
If you want to use ‘i’ as a subscript, it must consist only of integers greater than 0.
This example creates ‘iv’ (your ‘i’ vector in 0.1 increments, the centre value in the ‘iv’ definition), then loops through it, defining ‘NTU’ in each iteration as an element of ‘iv’:
NTUmax=10;
tt=100;
Soulution=zeros(tt,NTUmax);
iv = 1:0.1:NTUmax; %% Incrementing value should be e.g equal 0.1
for i = 1:numel(iv)
NTU = iv(i);
dtempdt=NTU*2;
Soulution(:,i)=dtempdt;
end
Experiment to get the result you want.
  2 件のコメント
Abdulaziz Gheit
Abdulaziz Gheit 2019 年 3 月 16 日
Thank you very much Star strider. You've been a great help.
Star Strider
Star Strider 2019 年 3 月 16 日
As always, my pleasure.

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

その他の回答 (0 件)

カテゴリ

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