cover_str = 'Great things in business done by one person. They done by a team of people.'
I want to split the above string into two sentences like
s1='Great things in business done by one person'.
s2='They done by a team of people'.
How can i do the above process in Matlab.
With regards.

 채택된 답변

KSSV
KSSV 2020년 10월 26일

0 개 추천

s = strsplit(cover_str,'.')

댓글 수: 9

Balkar Singh
Balkar Singh 2020년 10월 26일
Thanks sir.
Sir how can i store these sentence into two different varibles for further process.
KSSV
KSSV 2020년 10월 26일
Already they are in two different variables. S{1}, S{2}
Rik
Rik 2020년 10월 26일
Note that there can be multiple delimiters of sentences, depending on the language. These are the ones I could think of for English:
delim={'.','...','?','!','!,','!?','?!?','!?!'};
The latter four are debatable, but you probably get the idea. You could even consider adding obscure ones like the interobang (‽, see disp(char(8253)) to view the symbol in Matlab)
Especially the ellipsis is tricky: it is often redered as three dots (as I did above), or as the ellipsis character … (char 8230).
Paul
Paul 2020년 10월 26일
That command results in the cell array s with three elments because the last character in cover_str is the delimiter. The third element is empty.
>> strsplit(cover_str,'.').'
ans =
3×1 cell array
{'Great things in business done by one person'}
{' They done by a team of people' }
{0×0 char }
Also, you may want to consider just using split, though split doesn't seem to have quite as much functionality as strsplit.
>> split(string(cover_str),'.')
ans =
3×1 string array
"Great things in business done by one person"
" They done by a team of people"
""
Balkar Singh
Balkar Singh 2020년 10월 26일
Thank you very much sir..
Rik
Rik 2020년 10월 26일
You should also be careful if you have any decimal values in your sentences that use the period as decimal indicator. But that all depends on how robust you need this splitter to be.
Balkar Singh
Balkar Singh 2020년 10월 26일
Thank you sir..
But problem is that I am not able to find maximum occurrence of vowels in the split string. Please help
With regards
KSSV
KSSV 2020년 10월 26일
Read about strfind.
Balkar Singh
Balkar Singh 2020년 10월 27일
Ok Sir..Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

질문:

2020년 10월 26일

댓글:

2020년 10월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by