Hi i am getting Index out of bounds error pls help me solve it
4 ビュー (過去 30 日間)
古いコメントを表示
I hv a 2d image of 93×58 pixels. Error im gettin is attempted to access b(1,59) because size(b)=(93,58).
How do i go about rectifying this error?? Pls help as im new to matlab and to image processing. Thanks in advance.
2 件のコメント
採用された回答
Star Strider
2016 年 3 月 31 日
編集済み: Star Strider
2016 年 4 月 1 日
You’re asking for column 59 of a 58-column matrix.
Think about it ...
EDIT — Seeing only the part of your code that you posted (about 8 hours ago), I would simply reverse the values of ‘m2’ and ‘n2’ in your loops.
2 件のコメント
Star Strider
2016 年 4 月 4 日
In these lines:
m2 = m1*ms;
n2 = n1*ms;
the ‘ms’ variable has to be greater than 0 and less than or equal to 1 for that to work correctly.
The only way I can come up with to avoid addressing outside the dimensions of your image is with something like this:
m2 = fix(max(1,m2));
m2 = fix(min(m1,m2));
n2 = fix(max(1,n2));
n2 = fix(min(n1,n2));
That limits the index variables to the limits of your image size.
その他の回答 (2 件)
MHN
2016 年 3 月 31 日
So, you should not attempt to get b(1,59) when the size of b is (93,58) !!!
0 件のコメント
Walter Roberson
2016 年 4 月 1 日
Consider the possibility that you have m2 and n2 exchanged in your code.
Another possibility: did you use
[m2, n2] = size(YourMatrix)
and your image is a color image? If so then you have a bug because of the way that size() is defined when you have fewer outputs than the array has dimensions. Instead use
[m2, n2, ~] = size(YourMatrix)
2 件のコメント
参考
カテゴリ
Help Center および File Exchange で Image Processing Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!