How do I find all the words with a certain letter, when I have a cell array of strings?
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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)
0 Commenti
Risposte (1)
Image Analyst
il 5 Nov 2015
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
0 Commenti
Vedere anche
Categorie
Scopri di più su Characters and Strings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!