Hi,
First of all, there are a few errors with your userMorse variable. Every time you have typed "..--.-", which indicates a '-' character, there is an additional space before the /. This will cause errors with string matching.
Another change needed is the last / at the end of the userMorse variable must be omitted, otherwise, the split function returns one blank element at the end.
You can see the code below, where I have made some changes. It should work now. In the end, I am saving your results in a table, as it would visually appear nicely
clear all, close all,
clc
userMorse = '-.-./---/...-/../-../.----/----./..--.-/.--./.-/-./-.././--/../-.-./..--.-/...-/.-/-.-./-.-./../-./.';
code = {'.----','..---','...--','....-','.....','-....','--...','---..','----.','-----','.-',...
'-...','-.-.','-..','.','..-.','--.','....','..','.---','-.-','.-..','--','-.','---',...
'.--.','--.-','.-.','...','-','..-','...-','.--','-..-','-.--','--..', '..--.-'};
letter = {'1','2','3','4','5','6','7','8','9','0',...
'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','-'};
splitUserMorse = strsplit(userMorse,'/');
indexC = zeros(1,length(splitUserMorse));
%Convert morse code to string
for i = 1:length(splitUserMorse)
idx = find(strcmp(code,splitUserMorse{i}));
indexC(i) = idx;
end
s = letter(indexC);
freq = zeros(1,37);
%find frequency of each character in string
for i = 1:length(letter)
freq(i) = nnz(find(strcmp(s,letter{i})));
end
%SAve results in table
sz = [37 2];
varTypes = ["string","double"];
varNames = ["Letter","Frequency",];
tlb = table('Size',sz,'VariableTypes',varTypes,'VariableNames',varNames);
tlb(:,1) = letter';
tlb(:,2) = num2cell(freq)';