필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Getting an index out of bounds error in my matlab program. Please help. Stuck in this for quite a while now.

조회 수: 1 (최근 30일)
count = 0 ;
conn = zeros([],3) ;
for i=1:30
for j=1:27
count = count+1 ;
conn(count,:) =[j,j+1,j+2]
end
end
eltn=30
for i=1:27
for j=1:27
MG_matrix(conn(eltn,i) - 1,conn(eltn,j) - 1)= Mte_matrix(i,j); (ERROR HERE)
end
end
Attempted to access conn(3,4); index out of bounds because size(conn)=[810,3].
Error in practisee2 (line 558) MG_matrix(conn(eltn,i) - 1,conn(eltn,j) - 1)= Mte_matrix(i,j);

답변 (1개)

John D'Errico
John D'Errico 2018년 11월 5일
편집: John D'Errico 2018년 11월 5일
READ the error message. Look at what you are doing.
What size is conn? (810x3)
Where does the error message say the error arises?
for i=1:27
for j=1:27
MG_matrix(conn(eltn,i) - 1,conn(eltn,j) - 1)= Mte_matrix(i,j); (ERROR HERE)
In that last line. Hey, you got that right!
But what does it tell you? It says you were trying to access conn(3,4).
How are you indexing conn? conn(eltn,i) & conn(eltn,j)
What values do i and j take on? LOOK AT THE LOOP!!!!!!!!! It looks like both i and j vary as high as 27. And you are using them as the second index into a matrix that has only 3 columns.
What should MATLAB do when you do this? (Throw an error.)
What are you trying to do here? That I cannot guess. Uncommented code that does something totally arbitrary (and apparently wrong) is difficult to debug, since we have no idea what it is that you really needed to do.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by