sum columns with headers containing specific characters
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
dpb
le 18 Août 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 commentaire
Lei Hou
le 29 Août 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*'));
Voir également
Catégories
En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!