www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/DetermineIfStringStartsWithPatternExample.m

    %% Determine If String Starts with Pattern
% Create a string array that contains file names. Determine which file names 
% start with the word |data|.
str = string({'abstract.docx','data.tar','code.m';...
            'data-analysis.ppt','results.ptx','summary.ppt'})

%%
% Return a logical array where the position of each element equal to |1|
% corresponds to the position of a string in |str| that starts with |data|.
pattern = 'data';
TF = startsWith(str,pattern)

%%
% Display the file names that start with |data|. Index back into |str| using |Tf|.
str(TF)