How to extract info from a cell array using strsplit

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

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.
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 $.
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.)
If my answer did not work for you, then please indicate what difficulty you encountered.
(Answers Dev) Restored edit

Sign in to comment.

Answers (1)

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

Tags

Asked:

on 30 Sep 2020

Commented:

on 8 Oct 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!