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!