MATLAB Answers

Find all the words contained in a file and make an index

3 views (last 30 days)
Laura U
Laura U on 1 Oct 2019
Answered: Bob Nbob on 1 Oct 2019
I import from excel a file that contain all word and created the interested text string (d) :
num,txt,raw] = xlsread('words.xlsx','Hoja1');
d=string(txt);
>>d
d =
Media
Tao
When searching the web, I discovered that in case of being a word, I can do this, and it returns an index value with the location of that string
Index = find(contains(domain(:,1),'Tao'));
The problem is when I wanna use the file string interested as input (d). I make this e.g.
for (i = 1:d)
Index = find(contains(domain(:,1),d(i)))
end
But I receive this:
Index =
0×1 empty double column vector
I would very much appreciate any help you could give me.

  0 Comments

Sign in to comment.

Accepted Answer

Bob Nbob
Bob Nbob on 1 Oct 2019
You are on the right track, but you aren't calling the word index correctly. Also, I would suggest using strfind instead of the find(contains(domain( combo. I think it will just provide a more clean answer.
I am having some confusion with your variables, so I am outlining what I am using below. Adjust as you need to.
domain is the large string that you are search and finding indices within.
d is the list of words that you want to find. I am going to assume that it is a cell array of n x 1 size.
Index is the results, where the indices for each word are stored in a numeric array within a cell of Index. The cell number corresponds with the respective word in d.
for i = 1:size(d,1)
Index{i,1} = strfind(domain(:,1),d{i});
end

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.