MATLAB: Extract all columns from a table where the column names “start with” a string

extracttablewildcard

How can I extract all columns from a table where the column names "start with" a string?
For example, in
mytable = array2table(NaN(4,5));
mytable.Properties.VariableNames = {'A1', 'A2', 'B1', 'F2', 'F4'};
How would I extract all the "F*" columns in to a new table?

Best Answer

mask = startsWith( mytable.Properties.VariableNames, 'F');
Fcols = mytable(:,mask);