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

str = lower(str); % Make sure all letters are lowercase
if isletter(str(1)) % Check for an initial letter
str(1) = upper(str(1));
end
for k = 2:length(str) % Check each remaining letter
if isspace(str(k-1)) && isletter(str(k))
str(k) = upper(str(k));
end
end