フィルターのクリア

How do I find all the words with a certain letter, when I have a cell array of strings?

6 ビュー (過去 30 日間)
Rebecca Hussey
Rebecca Hussey 2015 年 11 月 4 日
回答済み: Image Analyst 2015 年 11 月 5 日
How do I find all the words with a certain letter(d), when I have a cell array of strings?
For example I have a shopping list. And I want to turn this into 0's and 1's. 1's being where a word is that contains this letter(d)

回答 (1 件)

Image Analyst
Image Analyst 2015 年 11 月 5 日
Try this:
ca = {'How' 'do' 'I' 'find' 'all' 'the' 'words' 'with' 'a' 'certain' 'letter'}
containsLetter = false(1, length(ca));
for k = 1 : length(ca)
if ~isempty(strfind(ca{k}, 'd'))
containsLetter(k) = true;
end
end
% Print to command window the indexes that have it
logicalIndexes = containsLetter
numericalIndexes = find(containsLetter)
See in command window:
ca =
'How' 'do' 'I' 'find' 'all' 'the' 'words' 'with' 'a' 'certain' 'letter'
logicalIndexes =
0 1 0 1 0 0 1 0 0 0 0
numericalIndexes =
2 4 7

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by