フィルターのクリア

End-of-array value entry

7 ビュー (過去 30 日間)
Maroulator
Maroulator 2014 年 8 月 11 日
コメント済み: Star Strider 2014 年 8 月 11 日
I have the following code which achieves what I need. However, when I tried to make it a bit more sophisticated and perform the substitution I note in the for statement below, I get no results. Cold someone please venture a guess as to why this is the case?
Io=2; K=1.38*(10^(-23)); q=1.602*(10^(-19)); id=-1:0.1:0.6;
for i=1:17 -----> substitute with for i=1:id(end)
T=75;
Vd(i)=((id(i)./Io)+1).*(exp(K*T)/q);
end

採用された回答

Star Strider
Star Strider 2014 年 8 月 11 日
Your id array has a maximum of 0.6. In your loop, i=1:0.6 would not execute because the value of the counter at the start, i=1 is already greater than the termination value, 0.6.

その他の回答 (1 件)

Hikaru
Hikaru 2014 年 8 月 11 日
Instead of substituting with
i=1:id(end)
Use:
i=1:length(id)
You also might want to preallocate Vd since it changes size in every iteration.
  2 件のコメント
Maroulator
Maroulator 2014 年 8 月 11 日
Hi Hikaru,
Unfortunately this website only allows me to award one "Accept" and it looks like Star Strider was first, so my apologies for not awarding anything to you. Your answer was really helpful all the same and I wanted to note that.
Star Strider
Star Strider 2014 年 8 月 11 日
@Maroulator — You can give him a vote (2 points).

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

カテゴリ

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