sum columns with headers containing specific characters
8 ビュー (過去 30 日間)
古いコメントを表示
I have a massive table called data, and need to add all columns with headers containing "A_side" into a new table, and then and need to add all columns with headers containing "B_side" into a new table how would i do that?
also, if i wanted to remove specific characters from all headers how would i do that?
0 件のコメント
回答 (1 件)
dpb
2022 年 8 月 18 日
tB=tData(:,contains(tData.Properties.VariableNames,'A_side'));
Should be able to figure out the other from that... :)
But, I'd submit that unless it really is so large that you're seeing notable performance issues that it's not necessary (nor wise) to create two separate tables but use logical addressing similar to above to address the columns needed instead within the one table.
As far as changing names, they're just a cell array of strings in the Properties.VariableNames struct; you can manipulate them with any of the string/pattern matching operations desired--you just have to ensure they are all unique.
1 件のコメント
Lei Hou
2022 年 8 月 29 日
Since R2022a, table indexing started to support pattern. To index to variables with headers containing "A_side", you can also use the following.
tB=tData(:,regexpPattern('\w*Size_A\w*'));
参考
カテゴリ
Help Center および File Exchange で Data Import from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!