Info

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

Index error during encryption

조회 수: 2 (최근 30일)
Braden Sasdelli
Braden Sasdelli 2019년 11월 12일
마감: MATLAB Answer Bot 2021년 8월 20일
im encrypting a message in an image and im having trouble getting the message to go through the cypher. i get an error at line 8 that says "Index exceeds the number of array elements (22)." and cant figure out how to fix it.
l = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',' '];
n = 1:27;
m = 'this is a test message';
d = 1;
em = zeros(1,length(m));
for i = 1:length(m)
for ele = 1:length(l)
if m(d)==l(ele)
em(d)=n(ele);
d=d+1;
end
end
  댓글 수: 1
Adam
Adam 2019년 11월 12일
Tick the 'Pause on errors' option in the run menu then just look at d in the workspace or command window when it stops. Apparently it is > 22.

답변 (1개)

Stijn Haenen
Stijn Haenen 2019년 11월 12일
You can use this script:
l = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',' '];
n = 1:27;
m = 'this is a test message';
d = 1;
em = zeros(1,length(m));
for i = 1:length(m)
em(i)=find(l==m(i));
end

Community Treasure Hunt

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

Start Hunting!

Translated by