Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Getting an index out of bounds error in my matlab program. Please help. Stuck in this for quite a while now.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
John D'Errico
le 5 Nov 2018
Modifié(e) : John D'Errico
le 5 Nov 2018
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 commentaires
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!