Split column in table
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Dion Theunissen
am 22 Jul. 2022
Bearbeitet: Ruger28
am 22 Jul. 2022
Hi.
I have the folowing table:

I want to split column 7 in 1 column only letters, and 1 column only the numbers. Anyone who can help me?
So 2 new columns. Column 13 will be LH, column 14 will be 0989.
0 Kommentare
Akzeptierte Antwort
Ruger28
am 22 Jul. 2022
Bearbeitet: Ruger28
am 22 Jul. 2022
This isn't the cleanest, but it works. I'm assuming that you always have some combination of 2 letters and then any amount of numbers after it.
TableNames = {'ID','Value'};
ID_Vals = [1;2];
Values = {'LH 1234';'QR1234'};
MyTable = table(ID_Vals,Values,'VariableNames',TableNames);
% Extract column and split it
ColVals = table2cell(MyTable(:,2));
SplitVals(:,1) = regexp(ColVals,'\w\w','match','once'); % look for 2 letters only
SplitVals(:,2) = regexp(ColVals,'\d+','match','once'); % look for a series of numbers only
% Add to table
MyTable.Letters = SplitVals(:,1); % place in table with the name Letters
MyTable.Numbers = SplitVals(:,2); % place in table with the name Numbers
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Find more on Logical 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!