Effacer les filtres
Effacer les filtres

How find a word in vector of words?

4 vues (au cours des 30 derniers jours)
huda nawaf
huda nawaf le 10 Août 2022
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.

Réponses (1)

Image Analyst
Image Analyst le 15 Avr 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"

Catégories

En savoir plus sur Discrete Data Plots dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by