function word = words(string)
%
%  $BEGIN
%  $HEADER words
%
%  Break a string into whitespace delimited words.
%  Produces a cell-array of strings. Individual strings are
%  accessed via s{1}, s{2}, and s{3}. Note the curly braces.
%
%  $HEADER REFERENCE
%  Notes from Cornell University
%  http://www.cs.cornell.edu/Courses/cs321/2003fa/project_1_notes.htm
%
%  $HEADER VERSION
%  1.0.0
%
%  Example
%  word = words(string)
%
%  See Also pdbReadFile
%  
%  $END
%

s = size(string,2);                  % Length of input string
blanks = find(isspace(string));      % Find indices of all whitespace
zblanks = [0 blanks];                % 0 counts as whitespace, too
n = size(zblanks,2);                 % Number of words (includes length 0)
length = [blanks s+1] - zblanks - 1; % Lengths of all words
result = cell(1,n);                  % Reserve space
for i = 1:n                          % Copy all words (includes length 0)
   result{1,i} = string(zblanks(i)+1:zblanks(i)+length(i));
end
word = result(length > 0);           % Remove length 0 words
