%% Translate Wildcard Characters
% Create a string array that contains file names. Then find only the file names that end with '.mat'.

str = ["test1.mat","myfile.mat","my-matlab-script.m", ...
       "jan30.mat","table3.xls"]

%
% To match strings with a regular expression, specify '*.mat' as the regular expression. Then translate the wildcard character, '*', using the regexptranslate function.

pattern = regexptranslate('wildcard','*.mat')

%
% Find matching elements in str using the regular expression specified by pattern.

matches = regexp(str,pattern)

%
% Create a logical array, TF, that contains 1 where corresponding elements of str matched pattern. Then index into str using TF to display the file names that end with '.mat'.

tf = ~cellfun('isempty',matches);
newStr = str(tf)

% Copyright 2012 The MathWorks, Inc.