Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 159069

Submitted on 7 Nov 2012 by Dieter

Correct

127Size
Leading solution size is 11.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
x = 'MATLAB is good';
y_correct = '--.--.-...--... ..... --.-------..';
assert(isequal(morseCoder(x),y_correct))
nu =
  Columns 1 through 10
    13     1    20    12     1     2   -32     9    19   -32
  Columns 11 through 14
     7    15    15     4
nu =
  Columns 1 through 10
    13     1    20    12     1     2     0     9    19     0
  Columns 11 through 14
     7    15    15     4
nu =
  Columns 1 through 10
    13     1    20    12     1     2     0     9    19     0
  Columns 11 through 14
     7    15    15     4
ystr =
-.-..-+..+----
-- --. .. ---.
   . .  . .--.
   . .
ystr =
--.--.-...--...+.....+--.-------..
ystr =
--.--.-...--... ..... --.-------..
2
Pass
 
%%
x = 'The quick brown fox jumps over the lazy dog';
y_correct = '-..... --.-..-..-.-.-.- -....-.---.---. ..-.----..- .---..---.--.... ---...-..-. -..... .-...---..-.-- -..-----.';
assert(isequal(morseCoder(x),y_correct))
nu =
  Columns 1 through 10
    20     8     5   -32    17    21     9     3    11   -32
  Columns 11 through 20
     2    18    15    23    14   -32     6    15    24   -32
  Columns 21 through 30
    10    21    13    16    19   -32    15    22     5    18
  Columns 31 through 40
   -32    20     8     5   -32    12     1    26    25   -32
  Columns 41 through 43
     4    15     7
nu =
  Columns 1 through 10
    20     8     5     0    17    21     9     3    11     0
  Columns 11 through 20
     2    18    15    23    14     0     6    15    24     0
  Columns 21 through 30
    10    21    13    16    19     0    15    22     5    18
  Columns 31 through 40
     0    20     8     5     0    12     1    26    25     0
  Columns 41 through 43
     4    15     7
nu =
  Columns 1 through 10
    20     8     5     0    17    21     9     3    11     0
  Columns 11 through 20
     2    18    15    23    14     0     6    15    24     0
  Columns 21 through 30
    10    21    13    16    19     0    15    22     5    18
  Columns 31 through 40
     0    20     8     5     0    12     1    26    25     0
  Columns 41 through 43
     4    15     7
ystr =
-..+-..--+-.-.-+.--+..-..+-...+-..+..--+---
 .  -.... .---. .-. -.--. -. -  .  ---. .--
 .  .- -- ..--  --. -- -. -. .  .  . .- .-.
 .  -  .  .     . - -  .   -    .  . .-
ystr =
-.....+--.-..-..-.-.-.-+-....-.---.---.+..-.----..-+.---..---.--....+---...-..-.+-.....+.-...---..-.--+-..-----.
ystr =
-..... --.-..-..-.-.-.- -....-.---.---. ..-.----..- .---..---.--.... ---...-..-. -..... .-...---..-.-- -..-----.
3
Pass
 
%%
x = '01234567890 is a pallindrome';
y_correct = '-----.----..---...--....-.....-....--...---..----.----- ..... .- .--..-.-...-....-.-...-.-----.';
assert(isequal(morseCoder(x),y_correct))
nu =
  Columns 1 through 10
   -16   -15   -14   -13   -12   -11   -10    -9    -8    -7
  Columns 11 through 20
   -16   -32     9    19   -32     1   -32    16     1    12
  Columns 21 through 28
    12     9    14     4    18    15    13     5
nu =
  Columns 1 through 10
   -16   -15   -14   -13   -12   -11   -10    -9    -8    -7
  Columns 11 through 20
   -16     0     9    19     0     1     0    16     1    12
  Columns 21 through 28
    12     9    14     4    18    15    13     5
nu =
  Columns 1 through 10
   -10    -9    -8    -7    -6    -5    -4    -3    -2    -1
  Columns 11 through 20
   -10     0     9    19     0     1     0    16     1    12
  Columns 21 through 28
    12     9    14     4    18    15    13     5
ystr =
-.....-----+..+.+.....--.--.
--.....---- .. - ----...---
---.....---  .   - ..  ..-
----.....--      . ..
-----.....-
ystr =
-----.----..---...--....-.....-....--...---..----.-----+.....+.-+.--..-.-...-....-.-...-.-----.
ystr =
-----.----..---...--....-.....-....--...---..----.----- ..... .- .--..-.-...-....-.-...-.-----.