Write a Matlab function called svapcodem that takes a string

Write a Matlab function called svapcode.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 = svapcode(svapcode(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 svapcode(\'This is a sentence.\') produces the string \'Gsrh rh z hvmgvmxv.\' Svapcode(\'Who has a 3-logged dog?\') produces the string \'Ds1 szh z 3-ovttvv vlt?\' svapcode(svapcode(*Dave97\')) produces the string \'Dave97\'

Solution

function str = swapcode(str)
idx = isstrprop(str,\'upper\');
str(idx) = char(155-str(idx));
idx = isstrprop(str,\'lower\');
str(idx) = char(219-str(idx));
end

 Write a Matlab function called svapcode.m that takes a string msg as input and returns another string coded as output. The function encodes the string by rever

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site