You get NaN because of this:
function edit1_Callback(hObject, eventdata, handles)
x=str2double(get(hObject,'String'));
set( handles.edit2,'String',num2str(x));
Let's say the message you entered is 'OK'. Look what happens when you do str2double('OK'):
because 'OK' is not a character representation of a number. If your message was '98' it would work fine:
So the correct thing to do is avoid str2double:
function edit1_Callback(hObject, eventdata, handles)
word = get(hObject,'String');
set(handles.edit2,'String',word);
Now, there's another problem:
[~, idx] = ismember(character, NumberOrLetter);
The second output from ismember is a vector of indices into the second input argument, i.e., idx is the indices in NumberOrLetter where that element of NumberOrLetter is character. idx will only be empty if character is empty (and character is never empty because it is one character from word). But idx can be 0; specifically, it is 0 if character does not exist in NumberOrLetter. So you mean to use idx ~= 0 there rather than ~isempty(idx).
You'll also want to do something with the Morse-code encoded message (wordToMorseCode), like display it somewhere in the GUI.
And you will find that lower-case letters in your message do not get encoded into Morse code; that's because they don't exist in NumberOrLetter (no numbers too). You can allow lower-case letters by using the upper function to convert word to all upper-case before encoding. (And you can allow numbers by including them in NumberOrLetter along with their Morse code symbol in morse.)