How find a word in vector of words?

4 次查看(过去 30 天)
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.

回答(1 个)

Image Analyst
Image Analyst 2023-4-15
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"

类别

Help CenterFile Exchange 中查找有关 Discrete Data Plots 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by