sum columns with headers containing specific characters

8 visualizaciones (últimos 30 días)
Olivia Gigliotti
Olivia Gigliotti el 18 de Ag. de 2022
Comentada: Lei Hou el 29 de Ag. de 2022
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?

Respuestas (1)

dpb
dpb el 18 de Ag. de 2022
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 comentario
Lei Hou
Lei Hou el 29 de Ag. de 2022
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*'));

Iniciar sesión para comentar.

Categorías

Más información sobre Data Import from MATLAB en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by