Error using sub2ind and error in imline/createMask ?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, while working with the below script I keep getting error message: Error using sub2ind (line 52) Out of range subscript. Error in imline/createMask (line 171) ind = sub2ind([m n], y, x); please can anyone help me with these error messages
0 commentaires
Réponse acceptée
Image Analyst
le 21 Juil 2015
sub2ind() does not appear in your attached code. So all I can suggest is that either m (the row) is greater than y (the number of rows), or n (the column) is greater than x (the total number of columns).
Another common problem is mixing up row,column with x,y.
4 commentaires
Image Analyst
le 23 Juil 2015
The code seems to have vanished. When an improper condition appears, it's always a judgment call by the Mathworks to try to fix the problem and try to recover, or to throw an error. I wonder what he did to get line endpoints outside the image. The function plot() will take points outside the image, but I guess they decided that createMask() should throw an error to let you know something's wrong. I bet they'd disagree about calling that behavior a bug.
Guillaume
le 24 Juil 2015
I consider it a bug in the sense that: a) the documentation never states that the endpoints should be within the image, and b) the error you get does not hint at all at what the problem may be.
I have actually reported it to mathworks and they "will consider changing it in a future release".
Note that it's fairly trivial to get endpoints outside the image, simply using the interactive tool.
Plus de réponses (1)
Guillaume
le 21 Juil 2015
The error message is indeed not very helpful, but the error is simply due to the fact that one or both endpoints of your line generated by imline are outside the boundaries of the image.
But first, fix the indenting of your file (right-click in the editor and select smart indent or just press CTRL+I). Once you've done that it'll be fairly obvious that your hline = imline(... and subsequent lines should be inside the for nn = ... loop. (or you've got a major conceptual failure in your code as, as it is, only the x1, x2, index1, etc. of the last iteration of the three loop will be used).
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!