フィルターのクリア

Why the function doesnt work with('1234')??!

1 回表示 (過去 30 日間)
Marco Nashaat
Marco Nashaat 2020 年 2 月 5 日
コメント済み: Marco Nashaat 2020 年 2 月 7 日
function coded=caesar(str,shift) a=double(str); counter=1; coded=zeros(1,length(str)); for i=[1:length(str)] if a(1,couner)+shift>126||a(1,counter)+shift<32%j while a(1,couner)+shift>126 coded(1,counter)=a(1,counter)+shift-95; counter=counter+1; end while a(1,counter)+shift<32 coded(1,counter)=a(1,counter)+shift+95; counter=counter+1; end else coded(1,counter)=a(1,counter)+shift; counter=counter+1; end end coded=char(coded) end
  7 件のコメント
Marco Nashaat
Marco Nashaat 2020 年 2 月 7 日
Wow how stupid of me!! Thank you very much
Marco Nashaat
Marco Nashaat 2020 年 2 月 7 日
I tried it now but it seems like it's not working yet,I got this message...Index in position 2 exceeds array bounds (must not exceed 4).
Error in caesar (line 7) while a(1,counter)+shift>126 Please help!!

サインインしてコメントする。

回答 (1 件)

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2020 年 2 月 5 日
solution:
save it :
function coded=caesar(str,shift)
a=double(str);
counter=1; coded=zeros(1,length(str));
for i=[1:length(str)]
if a(1,counter)+shift>126||a(1,counter)+shift<32%j
while a(1,couner)+shift>126
coded(1,counter)=a(1,counter)+shift-95;
counter=counter+1;
end
while a(1,counter)+shift<32
coded(1,counter)=a(1,counter)+shift+95;
counter=counter+1;
end
else
coded(1,counter)=a(1,counter)+shift;
counter=counter+1;
end
end
coded=char(coded);
end
and type it in the Command Window :
caesar('1234',2)
  4 件のコメント
JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2020 年 2 月 5 日
Walter Roberson sorry but it is not my solution is the same function provided by Marco Nashaat
Walter Roberson
Walter Roberson 2020 年 2 月 6 日
So it is, compete with the user of couner as a variable at one point.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by