Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

how to rectify this error and make the code work?

조회 수: 1 (최근 30일)
Anushree Bhatt
Anushree Bhatt 2015년 5월 7일
마감: MATLAB Answer Bot 2021년 8월 20일
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)

답변 (2개)

Joseph Cheng
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().

Geoff Hayes
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.
  댓글 수: 2
Anushree Bhatt
Anushree Bhatt 2015년 5월 8일
now there is no error but the code is not giving the desired output. i had entered the string 'hello' , on decryption i am supposed to get the value of 'hello' back at str . Instead i am getting a very weird value :
T,V.$.ze: N6MB`2F,
this is the value.
Anushree Bhatt
Anushree Bhatt 2015년 5월 8일
i tried a different thing .I changed the contents of the entire while loop. the following attached is the new code for decryption but it is not giving the desired output.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by