Merge Variables in Table
3 views (last 30 days)
Show older comments
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
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!