Effacer les filtres
Effacer les filtres

How to display each individual word of a string

6 vues (au cours des 30 derniers jours)
Bob
Bob le 5 Fév 2014
Commenté : Walter Roberson le 26 Déc 2017
hi all,
How can I display each word of a string individual? I wrote a loop, but it does not work.
  1 commentaire
Jan
Jan le 9 Fév 2014
How are the "words" separated? What about commas and full stops?

Connectez-vous pour commenter.

Réponses (3)

Mischa Kim
Mischa Kim le 5 Fév 2014
Use
my_str = strsplit('This is a test');
for ii = 1:length(my_str)
display(my_str{ii});
end

Azzi Abdelmalek
Azzi Abdelmalek le 5 Fév 2014
str='How to display each individual word of a string'
out=regexp(str,' ','split')
  1 commentaire
Bob
Bob le 6 Fév 2014
Modifié(e) : Bob le 9 Fév 2014
.

Connectez-vous pour commenter.


vikash kumar
vikash kumar le 26 Déc 2017
Modifié(e) : vikash kumar le 26 Déc 2017
word_loc = find(sentence==' ' | sentence =='.');
count = size(word_loc,2);
words = cell(count,1);
prev=1;
for i=1:count
words{i}= sentence(prev:word_loc(i)-1);
prev = word_loc(i)+1;
end
  1 commentaire
Walter Roberson
Walter Roberson le 26 Déc 2017
The difficulty with this is that it splits numbers like 3.14 and it splits abbreviations like "e.g."

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by