Next value in alphabet
17 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am trying to write a code to find a letter in the alphabet after the letter given, but I'm not sure which function specifies to choose the letter after. I've tried looking everywhere but I cant find it.
function [next] = nextLetter('char')
Alphabet = ('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';)
next = find(ismember(Alphabet, ???)
0 Commenti
Risposte (4)
VBBV
il 18 Gen 2023
Modificato: VBBV
il 18 Gen 2023
p = 'a' % e.g. user enters input letter
nextLetter(p) % output of nextLetter
function [next] = nextLetter(p)
Alphabet = {'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'};
next = find(ismember(Alphabet,p))+1; % add +1
next = Alphabet(next);
end
Voss
il 18 Gen 2023
nextLetter('d')
nextLetter('s')
nextLetter('z') % no next letter after 'z' -> error
function next = nextLetter(letter)
Alphabet = 'a':'z';
idx = find(Alphabet == letter)+1;
next = Alphabet(idx);
end
0 Commenti
Walter Roberson
il 19 Gen 2023
Modificato: Walter Roberson
il 19 Gen 2023
rot1('When is the time? The time for all good people, who come to the aid of their country!')
function next = rot1(letter)
Next(1:255) = char(1:255);
Next('a':'y') = 'b':'z';
Next('A':'Y') = 'B':'Z';
Next('z') = 'a';
Next('Z') = 'A';
next = Next(letter);
end
0 Commenti
Vedere anche
Categorie
Scopri di più su Structures in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!