1

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.

  • 1
    The function `strsplit` (equivalent) is available on [File Exchange](http://www.mathworks.com/matlabcentral/fileexchange/21710-string-toolkits/content/strings/strsplit.m) for use in old versions of Matlab. – Robert Seifert Feb 09 '14 at 21:46
  • possible duplicate of [How to display each individual word of a string?](http://stackoverflow.com/questions/21612308/how-to-display-each-individual-word-of-a-string) – nkjt Mar 20 '14 at 10:57

2 Answers2

3

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

strrep(s,' ',sprintf('\n'))
Daniel
  • 36,610
  • 3
  • 36
  • 69
2

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.

Luis Mendo
  • 110,752
  • 13
  • 76
  • 147