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

2 Ansichten (letzte 30 Tage)
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 Kommentare
James Tursa
James Tursa am 27 Sep. 2019
Rachael, it is considered rude to delete your question once you have answers.
Stephen23
Stephen23 am 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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 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.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by