function x = eng2PLword(x) % function x = eng2PLword(x) % S. Scott Moor, October 2007 % This is an improved function for translating single English words into % Pig Latin. The first letter will be capitalized if it was capitalized % in the orignial word. % % Input x = a single word string of at least 2 characters (no spaces) % Output x = the Pig Latin equivelent % Internal variables: % cons = a cell array of all lower-case consonants % vowel = a cell array of all lower-case vowels % determine if first letter is capitalized and save result a = (x(1) <95); % make all letters lower case and set up list of vowels & consonants x=lower(x); cons = {'b', 'c','d','f','g','h','j','k','l','m','n','p', 'q', 'r', ... 's', 't', 'v', 'w', 'x', 'z'}; vowel = {'a', 'e', 'i', 'o', 'u', 'y'}; % Initialzie flag for while loop i = 1; % Use while loop to move consonants to the end of the word until a vowel is % found. while i ==1 switch x(1) case cons x = [x(2:end),x(1)]; % move leading consonant to the end of the word case vowel i = 0; % change flag so loop is exited when vowel is found otherwise % display an error if letter is not found disp('ERROR: entered word has an element that is neither a consonant or a vowel') end end % add 'ay' to the end and capitalize the first letter if first letter was % capitalized in original word x = [x,'ay']; x(1) = x(1) - 32*a;