extract or split data from one column in table into several columns

3 ビュー (過去 30 日間)
DavidL88
DavidL88 2021 年 1 月 18 日
コメント済み: dpb 2021 年 1 月 18 日
Hi
I have a column with text data like below across multiple rows. I want to extract or split parts of this data into new columns. This data is not the same across all rows. Could anyone advise how to do this?
Ideally to get these 5 variables (separated here by /) into 5 columns
250ms,500ms / 95, 101, 106, 107 / Avg: 11_right / | bl | _HLG_MLD | (9) vs. Avg: 11_right | bl | _CG | _LOW (8) / FCL
from this data stored in one column as below
Perm t-test equal [250ms,500ms 95, 101, 106, 107]: Avg: 11_right | bl | _HLG_MLD | (9) vs. Avg: 11_right | bl | _CG | _LOW (8) | FCL
This data varies across rows but is in this same format, i.e it could be 11_right or 12_righ, etc, or could be FCL or POL, etc.
  4 件のコメント
Bob Thompson
Bob Thompson 2021 年 1 月 18 日
Does the split command do what you need it to then?
DavidL88
DavidL88 2021 年 1 月 18 日
Hi Bob
If I use InsertAfter to place / in the right positions and then use split it does. Thanks!

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

回答 (1 件)

dpb
dpb 2021 年 1 月 18 日
>> s='250ms,500ms / 95, 101, 106, 107 / Avg: 11_right / | bl | _HLG_MLD | (9) vs. Avg: 11_right | bl | _CG | _LOW (8) / FCL';
>> split(s,'/')
ans =
5×1 cell array
{'250ms,500ms ' }
{' 95, 101, 106, 107 ' }
{' Avg: 11_right ' }
{' | bl | _HLG_MLD | (9) vs. Avg: 11_right | bl | _CG | _LOW (8) '}
{' FCL' }
>>
As Bob says, if it's only to split the string on the delimiter, it's trivial...
  4 件のコメント
DavidL88
DavidL88 2021 年 1 月 18 日
Hi
It’s a matlab table with 4 columns. The data I want to split is in the first column. I thought simplest approach might be to insert / where I want to split using insertafter function and then split.
dpb
dpb 2021 年 1 月 18 日
Well, if you have a rule for what determines the string for determining the after in insertAfter that's fine. Is there a set of unique strings that can be determined to be in every string that can be used for the purpose? We only have one sample (and I'm not positive the representation in the forum is actually what it looks like in the file).
Are there no tabls, maybe, or is it actually a fixed-width file that might be simpler to just import by fixed column?

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

カテゴリ

Help Center および File ExchangeNumeric Types についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by