How do I circularly shift the alphabet without using circshift function?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (3)
Anand
le 21 Mar 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 commentaires
Azzi Abdelmalek
le 22 Mar 2013
Modifié(e) : Azzi Abdelmalek
le 22 Mar 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 commentaires
Voir également
Catégories
En savoir plus sur MATLAB Compiler dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!