Invalid index showing Index exceeds the number of array elements. Index must not exceed 1.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
shiv gaur
el 6 de Mzo. de 2022
Comentada: Jan
el 12 de Mzo. de 2022
a(1)=1;
b(1)=1;
c(1)=1;
S=0;
Z=0;
for i=1:20
for p=1:i-1
a(i+1)=(1/(i+1))*(a(i)-b(i));
S=S+a(p)*c(i-p);
b(i+1)=(1/(i+1))*(a(i)-S-b(i));
Z=Z+a(p)*b(i-p);
c(i+1)=(1/(i+1))*(Z-c(i));
disp([S Z])
end
end
Index exceeds the number of array elements. Index must not exceed 1.
display is showing
1 comentario
Jan
el 12 de Mzo. de 2022
@shiv gaur: You have been asked repeatedly to use a proper code formatting. Please read an consider this: https://www.mathworks.com/matlabcentral/answers/help/rtc#rtc_summary . Thanks.
Respuesta aceptada
Torsten
el 6 de Mzo. de 2022
For i=1, the p-loop is empty since your loop index goes from p=1:i-1.
Thus for i=1, a(i+1) = a(2), b(i+1) = b(2) and c(i+1) = c(2) will not be defined.
But for i=2, you refer to a(2), b(2) and c(2) in the p-loop in the expressions for a(3), b(3) and c(3). This causes the error.
13 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!