Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
how to rectify this error and make the code work?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
i am facing problem in the decryption code , however encryption code is working correctly. the error coming is : ??? Index exceeds matrix dimensions.
Error in ==> Decrypt_text at 15 while(im(x,y)~=0)&(x<q)&(y<p)
0 commentaires
Réponses (2)
Joseph Cheng
le 7 Mai 2015
for the error "index exceeds matrix dimensions" it is far simpler for you to debug it and learn from it. All you need to do is just put a debug breakpoint at that spot or a try-catch debug code to catch the error at which iteration.
Without digging all your code I can venture a guess just by looking at the error line. I am pretty certain you're incrementing x and y in the loop. And at some point you're doing x= x+1 or y = y+1 one too many times such that it no longer within the dimensions of im(). So to correct this your while conditional statement should be adjusted or pick when you're incrementing x or y such that you don't exceed dimensions of im().
0 commentaires
Geoff Hayes
le 7 Mai 2015
Anushree - since your p and q are determined by
[p,q,r]=size(I'm);
and your conditions for the while loop are
im(x,y)~=0&(x<q)&(y<p)
change the order of the conditions so that you check whether x and y are less than the number of rows and columns of im before you try to use them as indices into im. Try using
while x<=q && y<=p && im(x,y)~=0
Note that I've changed the conditions to allow for equality (maybe this isn't correct for your tests but they are still valid indices for im) and that I've replaced the & with && because it exhibits the short circuiting behaviour that the single ampersand does not.
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!