Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me (as soon as possible) writting a program that converts words to i

ID: 3768726 • Letter: P

Question

Please help me (as soon as possible) writting a program that converts words to its Morse code using Matlab. (You may use either a for loop or a while loop). For example, for a word 'AB', its Morse code is '.- -...' , since the Morse code of 'A' is '.-' and the Morse code of 'B' is '-...' . It is not correct to put '.-' and '-...' together without the space in between (i.e. '.--...').

MC_A='.-'; MC_B='-...'; MC_C='-.-.'; MC_D='-..'; MC_E='.'; MC_F='..-.'; MC_G='--.'; MC_H='....'; MC_I='..'; MC_J='.---'; MC_K='-.-'; MC_L='.-..'; MC_M='--'; MC_N='-.'; MC_O='---'; MC_P='.--.'; MC_Q='--.-'; MC_R='.-.'; MC_S='...'; MC_T='-'; MC_U='..-'; MC_V='...-'; MC_W='.--'; MC_X='-..-'; MC_Y='-.--'; MC_Z='--..';

Explanation / Answer

Working matlab code for the morse code:

inputstr = input ('Please enter the string to convert to morse code: ','s');
inputstr = upper(inputstr); %% converting the string to upper case
morse_dict={'.----','..---','...--','....-','.....','-....','--...','---..','----.','-----','.-','-...','-.-.','-..','.','..-.','--.','....','..','.---','-.-','.-..','--','-.','---','.--.','--.-','.-.','...','-','..-','...-','.--','-..-','-.--','--..','/'}; %% defining morse code for the characters
letter={'1','2','3','4','5','6','7','8','9','0','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','_'}; %%each character mapped to specific morse code
for i=1:length(inputstr)  
   [~, index] = ismember(inputstr(i), letter);
   if index > 0
       fprintf('%s ', morse_dict{index});      
   end  
end
fprintf(' ');      

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote