필터 지우기
필터 지우기

Index exceeds the number of array elements. Index must not exceed 0. Help with debugging.

조회 수: 3 (최근 30일)
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
Walter Roberson
Walter Roberson 2022년 12월 19일
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
h_simp = 5×10
5 1 1 4 5 8 2 2 4 6 8 3 9 8 2 6 6 9 2 5 3 7 9 9 3 6 7 3 9 7 5 7 9 8 1 8 2 7 3 9 6 6 5 7 4 6 7 9 5 1
Efrat Hazan Elimelech
Efrat Hazan Elimelech 2022년 12월 19일
Ok that’s interesting… I guess you get the same dimensions matrice when you print the I1_simp.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by