Index exceeds the number of array elements. Index must not exceed 0. Help with debugging.
Mostrar comentarios más antiguos
I just can't figure out what's wrong with the loop that this error occurs:
Index exceeds the number of array elements. Index must not exceed 0.
n_even=2:2:10;
x=1:10;
for j=1:length(n_even)
for k=1:length(x)
y(k)=8+4.*cos(x(k));
[h_simp(j,k),I1_simp(j,k)]=simpson13(@(x) 8+4.*cos(x(k)),0,y(k),n_even(j));
end
end
5 comentarios
Walter Roberson
el 19 de Dic. de 2022
Editada: Walter Roberson
el 19 de Dic. de 2022
I suspect the error is inside simpson13
Torsten
el 19 de Dic. de 2022
@(x) 8+4.*cos(x(k))
I doubt that "simpson13" calls the function with a vector of changing length for x.
Walter Roberson
el 19 de Dic. de 2022
But simpson13 might, for example, be written in terms of global variables... that are not initialized.
You can see from this experiment that the overall framework does not give the indexing error, so the problem must be in simpson13
simpson13 = @(f, p, q, r) deal(randi(9), randi(9));
n_even=2:2:10;
x=1:10;
for j=1:length(n_even)
for k=1:length(x)
y(k)=8+4.*cos(x(k));
[h_simp(j,k),I1_simp(j,k)]=simpson13(@(x) 8+4.*cos(x(k)),0,y(k),n_even(j));
end
end
h_simp
Efrat Hazan Elimelech
el 19 de Dic. de 2022
Respuestas (0)
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!