How to make a morse code decoder using ismember?
Afficher commentaires plus anciens
I have succesfully made a function to encode the statement AZ4M6NN0S789P to morse code. The series of dots and dashes were printed as a column vector for the final output. However I am trying to make a morse code decoder, which if I enter the column vector of dots and dashes, it should return "AZ4M6NN0S789P". I am trying to do this using ismember, and believe the solution could be similar to the code I used for the encoder function. Any suggestions on how to do this?
%my code for the encoder is as follows.
function encodedtext = morseEncoder()
text = input('Enter Characters to Encode \n','s' );
text = upper(text);
text = strjoin(strsplit(text));
code = {'.-';'-...';'-.-.';'-..';'.';'..-.';'--.';'....';'..';'.---';'-.-';'.-..';'--';'-.';'---';'.--.';'--.-';'.-.';'...';'-';'..-';'...-';'.--';'-..-';'-.--';'--..';'.----';'..---';'...--';'....-';'.....';'-....';'--...';'---..';'----.';'-----';'_'};
characters = {'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';'1';'2';'3';'4';'5';'6';'7';'8';'9';'0';''};
k =0 ;
for x=1:length(text)
[~,index]= ismember(text(x), characters);
if index >0
k = k +1 ;
fprintf('%s \n',code{index})
morseL{k} = code{index};
end
end
fprintf(morseL{k})
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!