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

5 visualizaciones (últimos 30 días)
Laura U
Laura U el 1 de Oct. de 2019
Respondida: Bob Thompson el 1 de Oct. de 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.

Respuesta aceptada

Bob Thompson
Bob Thompson el 1 de Oct. de 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

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by