How to read only vowels of a string
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Balkar Singh
el 24 de Abr. de 2020
Comentada: Balkar Singh
el 27 de Abr. de 2020
How can I read only vowels of a string by using regular expression in matlab. Thanks in advance.
0 comentarios
Respuesta aceptada
Tommy
el 24 de Abr. de 2020
Editada: Tommy
el 24 de Abr. de 2020
>> regexprep('How to read only vowels of a string?', '[^aeiouAEIOU]', '')
ans =
'ooeaooeoai'
>> char(regexp('How to read only vowels of a string', '[aeiouAEIOU]', 'match'))'
ans =
'ooeaooeoai'
(edit) No longer ignoring capitals!
6 comentarios
Tommy
el 26 de Abr. de 2020
Certainly, if you have the trimmed down character vector:
vowels = regexprep('How to read only vowels of a string?', '[^aeiouAEIOU]', '')
%{
vowels =
'ooeaooeoai'
%}
you could use histc:
bins = sort('aeiouAEIOU');
counts = histc(double(vowels), double(bins));
for v = bins
fprintf('%c: %d\n', v, counts(bins==v));
end
%{
A: 0
E: 0
I: 0
O: 0
U: 0
a: 2
e: 2
i: 1
o: 5
u: 0
%}
Más respuestas (0)
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!