Error Masg Matrix Dimensions exceeded
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am struggling over the above error msg. My code is below. Any hints app[reciated.
OptimalPath=zeros(40, 2);
iter=0;
M=1;
Row=1;
Col=1;
OptimalPath(M,1)=SearchSolution(SearchStart(1));
OptimalPath(M,2)=SearchSolution(SearchStart(2));
CurrentPos(M,1)=SearchSolution(SearchStart(1));
CurrentPos(M,2)=SearchSolution(SearchStart(2));
Min=SearchSolution(SearchStart(1),SearchStart(2));
while (Row < 8 & Col < 7)
while not(SearchSolution(Row,Col) == 1)
while not(SearchSolution(Row,Col) == 0)
iter = iter+1;
assert(maxIter>iter, 'maxIter assert triggered. Aborting.');
for X=1:1:3
for Y=1:1:3
if Min>CurrentPos(M(1),M(2));
Min=CurrentPos(M(1),M(2));
Row=X;
Col=Y; %capture the row and col corresp to the local min
end
end
end
CurrentPos(M,1)=Row;
CurrentPos(M,2)=Col;
end
end
Row=Row+1;
Col=Col+1;
M=M+1;
end
0 commentaires
Réponses (3)
Marc Jakobi
le 8 Oct 2016
Modifié(e) : Marc Jakobi
le 8 Oct 2016
This is causing your error:
if Min>CurrentPos(M(1),M(2));
Min=CurrentPos(M(1),M(2));
M is a 1x1 matrix, so M(2) exceeds M's dimensions.
You probably mean
if Min>CurrentPos(M,2);
Min=CurrentPos(M, 2);
or
if Min>CurrentPos(M,1);
Min=CurrentPos(M, 1);
2 commentaires
Marc Jakobi
le 8 Oct 2016
Modifié(e) : Marc Jakobi
le 8 Oct 2016
Go through the code line for line and see where the error shows up. Refer to Image Analyst's links (answer below) if you are unsure how to debug. "Index exceeds matrix dimensions" is a very common error in Matlab that should be easy to find.
Image Analyst
le 8 Oct 2016
Why are you saying this:
Row=X;
Col=Y; %capture the row and col corresp to the local min
This is opposite to the convention that the whole world uses.
You made the very common beginner mistake of thinking (x,y) = (row, column). It does not. If you're expecting (row, column), like you're indexing an array, then you need to use (y, x), NOT (x, y). Is that what you're doing? Take a very careful look at what your first index means and what you're passing in. If it's x, then pass in column. If it's row, then pass in y. Just make sure you're consistent.
0 commentaires
Image Analyst
le 8 Oct 2016
If that doesn't work, try this link before you ask again here, or call the Mathworks on the telephone for an immediate solution.
0 commentaires
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!