フィルターのクリア

How to display each individual word of a string

6 ビュー (過去 30 日間)
Bob
Bob 2014 年 2 月 5 日
コメント済み: Walter Roberson 2017 年 12 月 26 日
hi all,
How can I display each word of a string individual? I wrote a loop, but it does not work.
  1 件のコメント
Jan
Jan 2014 年 2 月 9 日
How are the "words" separated? What about commas and full stops?

サインインしてコメントする。

回答 (3 件)

Mischa Kim
Mischa Kim 2014 年 2 月 5 日
Use
my_str = strsplit('This is a test');
for ii = 1:length(my_str)
display(my_str{ii});
end

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 2 月 5 日
str='How to display each individual word of a string'
out=regexp(str,' ','split')
  1 件のコメント
Bob
Bob 2014 年 2 月 6 日
編集済み: Bob 2014 年 2 月 9 日
.

サインインしてコメントする。


vikash kumar
vikash kumar 2017 年 12 月 26 日
編集済み: vikash kumar 2017 年 12 月 26 日
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 件のコメント
Walter Roberson
Walter Roberson 2017 年 12 月 26 日
The difficulty with this is that it splits numbers like 3.14 and it splits abbreviations like "e.g."

サインインしてコメントする。

カテゴリ

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