How to extract info from a cell array using strsplit
Show older comments
ep = {'ELTOK' , 'HMR' , 'NILUG' , 'XILAN'}
How can I use strsplit to extract above words from the first column (cell array) of a table and how to get the count of each word (how many times each word was meantiond in that colounm).
example: I need to exclude all but these specific words 'ELTOK' , 'HMR' , 'NILUG' , 'XILAN' and i want to know the count of each of these words after exctracting.


5 Comments
Xingwang Yong
on 30 Sep 2020
It seems you already have these words extracted in your array ep, why do it again?
I assume you want to extract the rows which contain {'ELTOK' , 'HMR' , 'NILUG' , 'XILAN'}, the function contains() is helpful.
Xingwang Yong
on 30 Sep 2020
I am still confused about what words you want to extract.
In the orginal question, you said you want to extract words in the array ep= {'ELTOK' , 'HMR' , 'NILUG' , 'XILAN'}, now you said you want to extract 'ESSA', however 'ESSA' is not in the array ep.
Could you please specify the characteristics of the words you want to extract?
It seemed to me you want to extract words that is not lead by the $.
Walter Roberson
on 30 Sep 2020
Do you always want to exclude works that start with $ or * characters?
What would be an example entry that included HMR (the question being the format for words that are not 5 characters long.)
Walter Roberson
on 30 Sep 2020
If my answer did not work for you, then please indicate what difficulty you encountered.
Rena Berman
on 8 Oct 2020
(Answers Dev) Restored edit
Answers (1)
Walter Roberson
on 30 Sep 2020
targets = {'ELTOK' , 'HMR' , 'NILUG' , 'XILAN'}.';
temp = regexp(text1, '_', 'split');
temp = vertcat(temp{:});
[~, idx] = ismember(temp, targets);
counts = accumarray(idx(:)+1, 1); %words not in list will have idx 0
counts = reshape(counts(2:end),[],1); %first entry counted other words
results = table(targets, counts);
Categories
Find more on Cell Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!