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

5 Ansichten (letzte 30 Tage)
Laura U
Laura U am 1 Okt. 2019
Beantwortet: Bob Thompson am 1 Okt. 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.

Akzeptierte Antwort

Bob Thompson
Bob Thompson am 1 Okt. 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

Weitere Antworten (0)

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by