%% Determine If String Ends with Pattern
% Create a string array that contains file names. Determine which file names end with the .gz extension.
% Starting in R2017a, you can create strings using double quotes.

str = ["abstract.docx","data.tar.gz","mycode.m"; ...
       "data-analysis.ppt","results.ptx","temp-archive.gz"]

%
% Return a logical array where the position of each element equal to 1 corresponds to the position of a string in str that ends with .gz.

pattern = ".gz";
TF = endsWith(str,pattern)

%
% Display the file names that end with .gz. Index back into str using TF.

str(TF)

% Copyright 2012 The MathWorks, Inc.