Filter löschen
Filter löschen

Extract first x characters in specific table column and place them in new column.

35 Ansichten (letzte 30 Tage)
Hello,
i want to extract the first x characters of a specific column for every row in the table and create a new column with the extracts (see image).
Unfortunaly Im not able to do this...
Help is much appreciated!
  1 Kommentar
Chunru
Chunru am 30 Apr. 2021
Using table and string functions:
data = table(["aaaaaa"; "bbbbbbb"; "ccccccc"], [2.99; 2.99; 3.99]);
data.Properties.VariableNames=["Name", "Value"];
newName = extractBetween(data.Name, 1, 3);
data = addvars(data, newName);

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Chunru
Chunru am 30 Apr. 2021
data = table(["aaaaaa"; "bbbbbbb"; "ccccccc"], [2.99; 2.99; 3.99]);
data.Properties.VariableNames=["Name", "Value"];
newName = extractBetween(data.Name, 1, 3);
data = addvars(data, newName);
  3 Kommentare
Chunru
Chunru am 30 Apr. 2021
Something like this:
FirstWord = data.name; % copy the original name
for i = 1:length(FirstWord)
% Split each origninal name and get the first word
words = split(FirstWord(i));
FirstWord(i) = words(1);
end
data = addvars(data, FirstWord);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by