Extract first x characters in specific table column and place them in new column.
조회 수: 35 (최근 30일)
이전 댓글 표시
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).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/601730/image.bmp)
Unfortunaly Im not able to do this...
Help is much appreciated!
댓글 수: 1
Chunru
2021년 4월 30일
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);
채택된 답변
Chunru
2021년 4월 30일
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
Chunru
2021년 4월 30일
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);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!