For with a 0.1 step

96 ビュー (過去 30 日間)
Marc Sabaté
Marc Sabaté 2019 年 5 月 20 日
回答済み: Star Strider 2019 年 5 月 20 日
Sorry for this post because I'm sure that is a really simple thing. I'm trying to compute a function between 1 to 10 with a step of 0.1 with a for loop. I wrote it like this:
for i=1:0.1:10;
theta=0;
betha=1/(1/(i+0.08*theta)-0.035/(1+theta^3));
Cp(i)=C1*(C2/betha-C3*betha*theta-C4*theta-C5)*exp(-C6/betha);
end
Matlab gives me the error: Array indices must be positive integers or logical values.
I understant that the problem here is how the index is the defined but I don't know how to solve it
  1 件のコメント
Alexander Guth
Alexander Guth 2019 年 5 月 20 日
Just let i be an an integer index and multiply it with your step size inside the loop like this:
i * 0.1

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

採用された回答

Star Strider
Star Strider 2019 年 5 月 20 日
Indices must be integers greater than 0, or logicals.
Try this:
i=1:0.1:10;
for k = 1:numel(i)
theta=0;
betha=1/(1/(i(k)+0.08*theta)-0.035/(1+theta^3));
Cp(k)=C1*(C2/betha-C3*betha*theta-C4*theta-C5)*exp(-C6/betha);
end

その他の回答 (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