Info
此问题已关闭。 请重新打开它进行编辑或回答。
how to rectify this error and make the code work?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Joseph Cheng
2015-5-7
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 个评论
Geoff Hayes
2015-5-7
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.
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!