%% Include Dynamic Expression in Replacement Text
% Replace lowercase letters at the beginning of sentences with their uppercase equivalents using the upper function.

str = 'here are two sentences. neither is capitalized.';
expression = '(^|\.)\s*.';
replace = '${upper($0)}';

newStr = regexprep(str,expression,replace)

% The regular expression matches single characters (.) that follow the beginning of the character vector (^) or a period (\.) and any whitespace (\s*). The replace expression calls the upper function for the currently matching character ($0).
% Copyright 2012 The MathWorks, Inc.