フィルターのクリア

Tables: Create new variables by modifying existing ones

1 回表示 (過去 30 日間)
roblocks
roblocks 2016 年 5 月 19 日
コメント済み: roblocks 2016 年 5 月 19 日
Dear All,
I have a table and I would like to create new variables (columns) by modfying existing ones. I have seen examples where poeple apply functions, but these were typically restricted to numerical operations. Supoose I have the following table:
A B C
obs1 te:st X
obs2 test Y
I would like to create
A B C D
obs1 te:st X testX
obs2 test Y testY
So:
  1. Drop special characters (":")
  2. Append two string columns.
Can anyone help me out?
Thanks in advance!

採用された回答

Guillaume
Guillaume 2016 年 5 月 19 日
編集済み: Guillaume 2016 年 5 月 19 日
Use regexprep to replace patterns (with empty strings in your case), and strcat to concatenate cell arrays of strings:
t = cell2table({'obs1', 'te:st', 'X'; 'obs2', 'test', 'Y'}, 'VariableNames', {'A', 'B', 'C'})
t.D = strcat(regexprep(t.B, '\W', ''), test.C)
The regular expresion I've used will drop any character other than [a-ZA-Z0-9_]

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by