sub2ind -> out of range subscript

22 次查看(过去 30 天)
Hi ! I am a student and my project is about fingerprint analysis and minutia recognition. First, I have to understand each lines of the program sent by Florence Kussener : http://www.mathworks.com/matlabcentral/fileexchange/16728-fingerprint-application This application works great with the joined picture but when I download a new one, the program crashes with this error :
??? Error using ==> sub2ind at 58 Out of range subscript.
Do you have an idea ? The botch pictures are square and gray scale...I don't find the problem
Regards
PS : I am French and I my English is poor, sorry for that. And if you can answer me, please, I have to understand you so use a basic English

采纳的回答

Jean-Edouard Simonin
Thanks for your fast answer. It seems that with a square matrix the problem is solved (but I don't understand why). Unfortunately, some lines later a new problem :
??? Subscripted assignment dimension mismatch. Error in ==> fingerprint at 124 OrientationTerm(ind,1)=Table(i,j);
for ind=1:length(CentroidTermX) Klocal=K(CentroidTermY(ind)-2:CentroidTermY(ind)+2,CentroidTermX(ind)-2:CentroidTermX(ind)+2); Klocal(2:end-1,2:end-1)=0; [i,j]=find(Klocal); recherche des pixels (à l'intérieur de la fenêtre) à 1 restants OrientationTerm(ind,1)=Table(i,j); end
Do you know the source of the problem ?
  3 个评论
Walter Roberson
Walter Roberson 2011-3-24
It appears to me that Klocal might have more than one non-zero location. The find() would return multiple values in that case, and you would then try to store those multiple values in the single location OrientationTerm(ind,1)
You might want to use find(Klocal,1,'first')
Jean-Edouard Simonin
After verification, it seems you were right Walter. Indeed, there are sometimes more than one non-zero location, then it crashes !
Thak you very much for your help and have a nice day

请先登录,再进行评论。

更多回答(2 个)

Matt Fig
Matt Fig 2011-3-24
The error means exactly what it says. Here is an example where we try to access element (4,6) in a 3-by-3 matrix. It should produce the same error you experienced.
sub2ind([3,3],4,6)
Now as to why the program gets this error, it is hard to say. Perhaps the author hard-coded the conversion in and so when a new array is used that is smaller than the coding allows, the function errors.
  2 个评论
Walter Roberson
Walter Roberson 2011-3-24
The first argument to sub2ind() needs to be the array size, not the array itself...
Matt Fig
Matt Fig 2011-3-24
Thanks, Walter! I don't know how I missed that one, though it did give the 'correct' error for what I was doing...

请先登录,再进行评论。


Jean-Edouard Simonin
Thank you for your answers. I tried this part of code but the same problem comes again... Any other idea ?

类别

Help CenterFile Exchange 中查找有关 Numeric Types 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by