www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/DetermineIfStringEndsWithPatternExample.m
%% Determine If String Ends with Pattern % Create a string array that contains file names. Determine which file names % end with the |.gz| extension. str = string({'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)