sum columns with headers containing specific characters
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
dpb
il 18 Ago 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 Commento
Lei Hou
il 29 Ago 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*'));
Vedere anche
Categorie
Scopri di più su Data Import from MATLAB in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!