use regexp to split table columns?

Is there a way to split a table column containing text values as entries and return the newly split out contents as columns?
I have a table named Data with a column named TestID (Data.TestID). The following regexp command properly finds my text values and returns them:
OUT = regexp(Data.TestID, '(\w+-\w+)-\w{2}[-](\d+)\w*-','tokens')
Unfortunately, OUT is returned as a nx1 cell array where each cell contains a 1x1 cell array, each of these in turn contains a 1x2 cell array with my split strings inside. For example:
OUT{1,1}{1,1}
contains the two strings split out of the first entry of Data.TestID
Is there any way to split these strings so that OUT returns two columns that can be appended back onto Data?

2 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 8 月 24 日
post a sample of your data
MA
MA 2016 年 8 月 25 日
I ultimately found a solution (posted here)

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

 採用された回答

MA
MA 2016 年 8 月 25 日

1 投票

I ultimately found a solution using 'names' to split the output into a structure that I could convert into a table:
OUT = regexp(Data.TestID(:,1), '(?<Name1>\w+-\w+)-\w{2}-(?<Name2>\d+)\w*-\w{2}', 'names');
OUT = [OUT{:}];
OUTTable = struct2table(OUT);
this let me append OUTTable to Data using:
Data = [Data OUTTable];

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeText Data Preparation についてさらに検索

製品

タグ

質問済み:

MA
2016 年 8 月 24 日

コメント済み:

MA
2016 年 8 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by