Extract all columns from a table where the column names "start with" a string
143 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
採用された回答
Walter Roberson
2019 年 8 月 28 日
mask = startsWith( mytable.Properties.VariableNames, 'F');
Fcols = mytable(:,mask);
その他の回答 (1 件)
Arnaud Delorme
2022 年 5 月 27 日
編集済み: Arnaud Delorme
2022 年 5 月 27 日
colNames = fieldnames(mytable);
[~,inds] = intersect(colNames, { 'A1' 'A2' } );
mytable = mytable(:,sort(inds));
1 件のコメント
Walter Roberson
2022 年 5 月 27 日
This would not get you anything that mytable(:, { 'A1' 'A2' } ) would not give, other than preserving relative order of variables.
参考
カテゴリ
Help Center および File Exchange で Design Scripting についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!