CS112: Lab 9 :: More practice with Strings

Today you'll be working in pairs to write code for these two tasks. The goal is to strengthen your string manipulation skills in MATLAB.

Task 1: Phonetic translation

Write a function that will translate a given string into a string made up of the corresponding words of the International phonetic alphabet (listed below). The phonetic alphabet:

Alpha Bravo Charlie Delta Echo Foxtrot Golf Hotel India Juliet Kilo Lima Mike November Oscar Papa Quebec Romeo Sierra Tango Uniform Victor Whiskey X-ray Yankee Zulu

Your function can only have one loop: the loop through the given string.
Here are some examples:

>> result1 = translatePhonetic('Sohie')
 result1 = 
  Sierra Oscar Hotel India Echo

>> result2 = translatePhonetic('elmo')
result2 =
 Echo Lima Mike Oscar

>> result3 = translatePhonetic('cs112')
result3 =
 Charlie Sierra   

>> result4 = translatePhonetic()
Please enter a string for phonetic translation
result4 =
     ''

>> result5 = translatePhonetic('flower')
result5 =
 Foxtrot Lima Oscar Whiskey Echo Romeo

>> result6 = translatePhonetic(result5(1:9))
result6 =
   Foxtrot Oscar X-ray  Tango Romeo Oscar Tango
>> 

Task 2A: containsDuplicate with a while loop

Write a function that returns true (1) if the given string contains a duplicate character, false (0) otherwise. Some examples (note that a space counts as a character):
>> res = containsDuplicate('simon')
res =
     0
>> res = containsDuplicate('ellen')
res =
     1
>> res = containsDuplicate('kara')
res =
     1
>> res = containsDuplicate('randy')
res =
     0
>> res = containsDuplicate('american')
res =
     1
>> res = containsDuplicate('encyclopedia')
res =
     1
>> res = containsDuplicate('I am ')
res =
     1
>> res = containsDuplicate('uncopyrightable')
res =
     0
>> res = containsDuplicate('dermaglyphics')
res =
     0
>> res = containsDuplicate('!@\#$')
res =
     0

Task 2B: containsDuplicate with a for loop

Rewrite containsDuplicate so that it has the same functionality, but uses a for loop instead of a while loop.

Task 3: Continue working on drawGUI

Here's the link to GUI problem in assignment 6.

Here's a hint about the undo button. Everytime MATLAB makes a plot, it stores a handle to that plot. If you save all the handles each time something is plotted, then you can use those handles to undo.

Here is an example:


>> h1 = plot(1:10)
h1 =
  171.0045
>> hold on
>> h2 = plot(10:-1:1,'m*:')
h2 =
  172.0040

>> delete(h1)
>>