user3281110
user3281110

Reputation: 31

How to display each individual word of a string in MATLAB

How to display each individual word of a string in MATLAB version R2012a? The function strsplit doesn't work in this version. For example 'Hello, here I am'. I want to display every word on a single line.

Upvotes: 1

Views: 158

Answers (2)

Luis Mendo
Luis Mendo

Reputation: 112659

You can use regexp with the 'split' option:

>> str = 'Hello, here I am';
>> words = regexp(str, '\s+', 'split').'

words = 

    'Hello,'
    'here'
    'I'
    'am'

Change '\s+' to a more elaborate pattern if needed.

Upvotes: 2

Daniel
Daniel

Reputation: 36710

Each word in a single line means replacing each blank with a new line:

strrep(s,' ',sprintf('\n'))

Upvotes: 3

Related Questions