How find a word in vector of words?

5 visualizzazioni (ultimi 30 giorni)
huda nawaf
huda nawaf il 10 Ago 2022
Risposto: Image Analyst il 15 Apr 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.

Risposte (1)

Image Analyst
Image Analyst il 15 Apr 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"

Categorie

Scopri di più su Discrete Data Plots in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by