Merge Variables in Table
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Alexandra Kopaleyshvili
il 12 Giu 2021
Modificato: Alexandra Kopaleyshvili
il 13 Giu 2021
I would like to create a for loop which can merge variables dynamically by first letter, excluding the number standing behind the letter.
from this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/650945/image.png)
to this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/650950/image.png)
Thanks!
0 Commenti
Risposta accettata
Walter Roberson
il 13 Giu 2021
names = YourTable.Properties.VariableNames;
initials = extractBefore(names, 2);
[G, id] = findgroups(initials);
newTable = table();
for K = 1 : length(id)
newTable.(id{K}) = [YourTable{:,G==K}];
end
2 Commenti
Alexandra Kopaleyshvili
il 13 Giu 2021
Modificato: Alexandra Kopaleyshvili
il 13 Giu 2021
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Tables 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!