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

2 vues (au cours des 30 derniers jours)
Rachael
Rachael le 20 Sep 2019
Commenté : Stephen23 le 28 Sep 2019
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 commentaires
James Tursa
James Tursa le 27 Sep 2019
Rachael, it is considered rude to delete your question once you have answers.
Stephen23
Stephen23 le 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

Connectez-vous pour commenter.

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by