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

2 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by