How find a word in vector of words?

3 visualizaciones (últimos 30 días)
huda nawaf
huda nawaf el 10 de Ag. de 2022
Respondida: Image Analyst el 15 de Abr. de 2023
Hello.
How can I find a word in a long vector of words, for example:
x={'shoemoney'
'devices'
'mcburnett'
'gdri'
'ezralevant'
'Winston80'
'daniellean'
'geokem7'}
x = 8×1 cell array
{'shoemoney' } {'devices' } {'mcburnett' } {'gdri' } {'ezralevant'} {'Winston80' } {'daniellean'} {'geokem7' }
How do I find the locations of gdri?
Thanks in advance.

Respuestas (1)

Image Analyst
Image Analyst el 15 de Abr. de 2023
Try this:
wordList = {'shoemoney'
'devices'
'mcburnett'
'gdri'
'ezralevant'
'Winston80'
'daniellean'
'geokem7'
'abs gdri def'};
logIndexes = contains(wordList, 'gdri'); % Logical vector.
linearIndexes = find(logIndexes) % Convert to only the indexes that are 1 for the logical index value.
linearIndexes = 2×1
4 9
for k = 1 : length(linearIndexes)
thisIndex = linearIndexes(k);
fprintf('gdri shows up in item #%d : "%s"\n', thisIndex, wordList{thisIndex})
end
gdri shows up in item #4 : "gdri" gdri shows up in item #9 : "abs gdri def"

Categorías

Más información sobre Discrete Data Plots en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by