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);
0 个评论
回答(1 个)
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.
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!