Error Masg Matrix Dimensions exceeded
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (3 件)
Marc Jakobi
2016 年 10 月 8 日
編集済み: Marc Jakobi
2016 年 10 月 8 日
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 件のコメント
Marc Jakobi
2016 年 10 月 8 日
編集済み: Marc Jakobi
2016 年 10 月 8 日
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
2016 年 10 月 8 日
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 件のコメント
Image Analyst
2016 年 10 月 8 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!