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?

回答(1 个)

dpb
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
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 CenterFile Exchange 中查找有关 Data Import from MATLAB 的更多信息

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by