Write a Mat lab function called swapcodem that takes a strin
     Write a Mat lab function called swapcode.m that takes a string msg as input and returns another string coded as output. The function encodes the string by reversing the alphabet: it replaces each \'a\' with \'z\', each \'b\' with \' y\', each \'c\' with \'x\', etc. The function must work for uppercase letters the same way. but it must not change any other characters. Note that if you call the function twice like this txtout  swapcode(swapcode(txtin)) then the string stored in txtout will be identical to the string stored in txtin. The specifications for the function and some sample function calls are shown below.  input parameter msg a string  output parameter coded a string  sample function calls  swapcode (\' This is a sentence.\') Produces the string \'Gsrh rh z hvmgvmxv.\'  swapcode (\'who has a 3-1egged dot?\') produces the string \'Ds1 szh z 3-ovttwv wlt?\'  swapcode 9swapcode 9\' dave97\')) Produces the string \'Dave97\' 
  
  Solution
Here is the code for you:
function coded = swapcode(msg)
coded = \'\';
upperCase = [\'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\'];
lowerCase = [\'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\'];
for i = 1 : length(msg)
if(isletter(msg(i)))
if(ismember(msg(i), upperCase))
temp = fliplr(upperCase);
pos = find(upperCase==msg(i));
coded = strcat(coded, temp(pos));
else if(ismember(msg(i), lowerCase))
temp = fliplr(lowerCase);
pos = find(lowerCase==msg(i));
coded = strcat(coded, temp(pos));
else
coded = strcat(coded, msg(i));
end
end
end
end
end

