フィルターのクリア

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).
Unfortunaly Im not able to do this...
Help is much appreciated!
  1 件のコメント
Chunru
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
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
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);
Simon Schmidt
Simon Schmidt 2021 年 4 月 30 日
Great, thanks a lot!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by