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!

 採用された回答

Walter Roberson
Walter Roberson 2021 年 6 月 13 日

1 投票

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 件のコメント

Alexandra Kopaleyshvili
Alexandra Kopaleyshvili 2021 年 6 月 13 日
Hey Walter, thank you very much!
Is it possible to combine those multicolumn variables (like B or L) into single-column-variables (as shown in the second picture)?
Alexandra Kopaleyshvili
Alexandra Kopaleyshvili 2021 年 6 月 13 日
編集済み: Alexandra Kopaleyshvili 2021 年 6 月 13 日
Ok i got it! I just needed to add this to your code:
for jj=1:width(newTable)
size(newTable.(jj))
if ans(1,2)> 1
alinear = {newTable.(jj){:}}'
{cat(1, alinear{:})}
newTable.(jj)=ans
end
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by