Info
此问题已关闭。 请重新打开它进行编辑或回答。
Index error during encryption
2 次查看(过去 30 天)
显示 更早的评论
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
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
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!