MATLAB: How to get rid of spaces between string

for loopnested loopstrstrtrimswitch construct

I have to work out a way to remove the spaces in my morse code output. SO far I have something like this:
...
Word=input('Please enter a word:','s');
Word=upper(Word);
Valid=1;
str = ' ';
for Character=Word
switch Character
...
case ' '
Code='/';
otherwise
Valid=0;
end

Best Answer

Pam: You have two options:
Option (1) MC_1 ... MC_Z had a white space at end of them. Remove them. If I remember correctly change MC_1='.---- ' to MC_1='.----' , i.e. removing the space at the end. Then there would be no space in to begin with, so there is no need to remove them anymore
Pretty much change this part of your code:
MC_1='.---- '; MC_2='..--- '; MC_3='...-- ';
MC_4='....- '; MC_5='..... '; MC_6='-.... ';
MC_7='--... '; MC_8='---.. '; MC_9='----. ';
MC_0='----- '; 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='--.. ';
to
MC_1='.----'; MC_2='..---'; MC_3='...--';
MC_4='....-'; MC_5='.....'; MC_6='-....';
MC_7='--...'; MC_8='---..'; MC_9='----.';
MC_0='-----'; 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='--..';
If you are still using the code that you asked before.
Option (2) If
Word='-. --- / .... ..'
So it has spaces, the easiest way to remove the spaces is this:
Word=Word(Word~=' ');