With this code in the pushbutton callback, i only can detect the edit text last word, which when i key in a it will be translated to '.-' but with ab it only translate the b which i '-…' same goes to morse to letter. How do i translate the whole thing? Should i make a new array and loop outside ? how do this actually works? Need help! Hope for replies asap.
a = get(handles.edit1,'string');a = upper(a);a = strjoin(strsplit(a));b = get(handles.popupmenu1,'value');k=0;morse = {'.-','-...','-.-.','-..','.','..-.','--.','....','..','.---','-.-','.-..','--','-.','---','.--.','--.-','.-.','...','-','..-','...-','.--','-..-','-.--','--..','.-.-.-','/'};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','Stop',''};switch b case 1 set(handles.edit1,'string',''); set(handles.text4,'string',''); case 2 for i=1:length(a) [~,j] = ismember(a(i),letter); if j > 0 set(handles.text4,'string',morse{j}); end end case 3 for i=1:length(a) [~,j] = ismember(a(i),morse); if j > 0 set(handles.text4,'string',letter{j}); end end end
Best Answer