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

2 views (last 30 days)
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 Comments
James Tursa
James Tursa on 27 Sep 2019
Rachael, it is considered rude to delete your question once you have answers.
Stephen23
Stephen23 on 28 Sep 2019
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

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 20 Sep 2019
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.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!