Merge Variables in Table
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Alexandra Kopaleyshvili
le 12 Juin 2021
Modifié(e) : Alexandra Kopaleyshvili
le 13 Juin 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 commentaires
Réponse acceptée
Walter Roberson
le 13 Juin 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 commentaires
Alexandra Kopaleyshvili
le 13 Juin 2021
Modifié(e) : Alexandra Kopaleyshvili
le 13 Juin 2021
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Tables 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!