function str = capitalize(str)
% Post: Convert string so each word has just first letter capitalized
% Pre: Input string consists entirely of letters & spaces

% Written by Paul Chew for CS100M, Feb 2006

str = lower(str);       % Make sure all letters are lowercase
previous = ' ';
for k = 1:length(str)   % Check each letter
    if previous == ' ' && isletter(str(k))
        str(k) = upper(str(k));
    end
    previous = str(k);
end
