How find a word in vector of words?

3 Ansichten (letzte 30 Tage)
huda nawaf
huda nawaf am 10 Aug. 2022
Beantwortet: Image Analyst am 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.

Antworten (1)

Image Analyst
Image Analyst am 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"

Kategorien

Mehr zu Discrete Data Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by