How do I circularly shift the alphabet without using circshift function?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I'm trying to write a function that inputs the alphabet then shifts it by 3 so that then the original would be ABC...XYZ and then with the shift it'd look like XYZ...UVW.
Thanks for the help!
___________
Ok I typed this into matlab and it worked. I tried it again for a message that I want to shift 12 letters over, but it won't work.
lets say for example my message was: I HATE MATLAB.
How would i do a function so that the spaces and the punctuation would stay the same, but the message would then read: U TMFQ YMFXMN.
thanks again!
0 Kommentare
Antworten (3)
Anand
am 21 Mär. 2013
alphabet = 97 : 122;
>> char(alphabet)
ans =
abcdefghijklmnopqrstuvwxyz
shifted_alphabet = alphabet-3;
shifted_alphabet(1:3) = alphabet(end-2:end);
>> char(shifted_alphabet)
ans =
xyzabcdefghijklmnopqrstuvw
0 Kommentare
Azzi Abdelmalek
am 22 Mär. 2013
Bearbeitet: Azzi Abdelmalek
am 22 Mär. 2013
shiftn=12
s='A':'Z';
str='I HATE MATLAB'
idx=regexp(str,'[A-Z]')
for k=idx
a=strfind(s,str(k))
str(k)=s(mod(a+shiftn,26))
end
%or
shiftn=12
str='I HATE MATLAB'
sth=double(str)-64
idx=regexp(str,'[A-Z]')
sth(idx)=mod(sth(idx)+shiftn,26)
out=char(sth+64)
0 Kommentare
Siehe auch
Kategorien
Mehr zu MATLAB Compiler finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!