How to convert cell in a string
Show older comments
function [letter] = morse_decoder(code)
morse = {'10111', '111010101', '11101011101', '1110101', '1', '101011101', '111011101', '1010101', '101', '1011101110111', '111010111', '101110101', '1110111', '11101', '11101110111', '10111011101', '1110111010111', '1011101', '10101', '111', '1010111', '101010111', '101110111','11101010111', '1110101110111', '11101110101'};
str_letter ={'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'};
i = length(code)
for n =1:i
[~,index] = ismember(code(n),morse);
letter = str_letter(index);
end
end
m-file
[word,space1] = split(code,["0000000"]);
[alphabet1,space2] = split(word(1),["000"]);
q = length(alphabet1);
for n = 1:q;
letter1(n) = morse_decoder(alphabet1(n,1));
end
[alphabet2,space2] = split(word(2),["000"]);
w = length(alphabet2);
for n = 1:w;
letter2(n) = morse_decoder(alphabet2(n,1));
end
[alphabet3,space2] = split(word(3),["000"]);
r = length(alphabet3);
for n = 1:r;
letter3(n) = morse_decoder(alphabet3(n,1));
end
[alphabet4,space2] = split(word(4),["000"]);
t = length(alphabet4);
for n = 1:t;
letter4(n) = morse_decoder(alphabet4(n,1));
end
[alphabet5,space2] = split(word(5),["000"]);
y = length(alphabet5);
for n = 1:y;
letter5(n) = morse_decoder(alphabet5(n,1));
end
[alphabet6,space2] = split(word(6),["000"]);
u = length(alphabet6);
for n = 1:u;
letter6(n) = morse_decoder(alphabet6(n,1));
end
[alphabet7,space2] = split(word(7),["000"]);
p = length(alphabet7);
for n = 1:p;
letter7(n) = morse_decoder(alphabet7(n,1));
end
b = strrep(space1,'0000000',' ');
c = strrep(space2,'000','');
v1 = {letter1};
str_code1 = strjoin(letter1);
str_code2 = strjoin(letter2);
str_code3 = strjoin(letter3);
str_code4 = strjoin(letter4);
str_code5 = strjoin(letter5);
str_code6 = strjoin(letter6);
str_code7 = strjoin(letter7);
Decode_code = {str_code1 str_code2 str_code3 str_code4 str_code5 str_code6 str_code7}
the input code is 111010111010001110111011100011101000111011101000101110100010111000111000101011100010111010100010111000111000101000111011101110001110100010101000000011101011101110001110111011100010101110000000101010100010111000101010111000100000001010100010101110001110101110100011101011101000100010101000101010001010111010001010111000101110101000101110101000111010111011100000001110101000100011101011101000111011101110001110101000100011101010000000111000101010100010000000111011100010001010100010101000101110001110111010001
So i had decode the message and my output is in terms of cells as shown below. Does anyone know how to i convert into srting so that i can fprintf my sentence, i had tried with many functions but it doesn't work in my case. i want my sentence to be like, 'congratulations you have successfully decoded the message'.
.png)
1 Comment
Star Strider
on 14 Jan 2020
Accepted Answer
More Answers (0)
Categories
Find more on Web Services in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!