Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Index error during encryption

2 visualizzazioni (ultimi 30 giorni)
Braden Sasdelli
Braden Sasdelli il 12 Nov 2019
Chiuso: MATLAB Answer Bot il 20 Ago 2021
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 Commento
Adam
Adam il 12 Nov 2019
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.

Risposte (1)

Stijn Haenen
Stijn Haenen il 12 Nov 2019
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