Info
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
how to rectify this error and make the code work?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (2)
Joseph Cheng
il 7 Mag 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 Commenti
Geoff Hayes
il 7 Mag 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.
Questa domanda è chiusa.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!