put your current code in a function such as
function outputMorse=char2morse(inputeChar)
So this function gets a character and returns the morse code. Put your code that you have there. Name that file char2morse.m (or whatever you gonna name that function.
Then write another code
function outputMorse=string2morse(inputString)
validateattributes(inputString,{'char'},{'vector'})
for i=1:numel(inputString)
outputMorse{i}=char2morse(inputString(i));
end
put this in a file called string2morse.m (or again whatever you want to name this function.)
Now you can call this function in other codes like:
morseCode=string2morse('SOS')
NOTE: Based on your code and output type you need to change the above code. But the general structure would be like that.
Best Answer