Index exceeds the number of array elements (1) error on line 10

2 ビュー (過去 30 日間)
Rachael
Rachael 2019 年 9 月 20 日
コメント済み: Stephen23 2019 年 9 月 28 日
input('What parameter file do you want to use?'); % type parameters
P3(1:300) = P3d;
P3(301:500) = P3s;
for i = 1:N;
P2(i) = (V2(i)-Vr)/C2;
if P3(i)>P2(i); Q3(i) = (P3(i)-P2(i))/R2;
else Q3 = 0;
end
Q1(i) = (P2(i)-P1)/R1;
Q2(i) = Q1(i)-Q3(i);
V2(i+1) = V2(i)+Q2(i)*dt;
end
  2 件のコメント
James Tursa
James Tursa 2019 年 9 月 27 日
Rachael, it is considered rude to delete your question once you have answers.
Stephen23
Stephen23 2019 年 9 月 28 日
Original Question (in case it gets deleted again):
Index exceeds the number of array elements (1) error on line 10
input('What parameter file do you want to use?'); % type parameters
P3(1:300) = P3d;
P3(301:500) = P3s;
for i = 1:N;
P2(i) = (V2(i)-Vr)/C2;
if P3(i)>P2(i); Q3(i) = (P3(i)-P2(i))/R2;
else Q3 = 0;
end
Q1(i) = (P2(i)-P1)/R1;
Q2(i) = Q1(i)-Q3(i);
V2(i+1) = V2(i)+Q2(i)*dt;
end

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

採用された回答

Walter Roberson
Walter Roberson 2019 年 9 月 20 日
if P3(i)>P2(i); Q3(i) = (P3(i)-P2(i))/R2;
else Q3 = 0;
end
The else of that overwrites all of Q3 with a scalar value. It would no longer have length greater than 1 for the Q3(i) reference further down.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by