Merge Variables in Table
1 view (last 30 days)
Show older comments
Alexandra Kopaleyshvili
on 12 Jun 2021
Edited: Alexandra Kopaleyshvili
on 13 Jun 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:
to this:
Thanks!
0 Comments
Accepted Answer
Walter Roberson
on 13 Jun 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
More Answers (0)
See Also
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!