How To Convert data separated by commas into columns.

I have imported a dataset from UCi and it is in .data format. How do i separate these data into separate columns.
Look at an example of two rows below:
{'58, Self-emp-inc, 181974, Doctorate, 16, Never-married, Prof-specialty, Not-in-family, White, Female, 0, 0, 99, ?, <=50K'}
{'50, Private, 485710, Doctorate, 16, Divorced, Prof-specialty, Not-in-family, White, Female, 0, 0, 50, United-States, <=50K'}

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 11 月 2 日

0 投票

Try this
str = fileread('data.txt');
data = strrep(str, '{''', '');
data = strrep(data, '''}', ', ');
data = strrep(data, newline, '');
data = strsplit(data, ', ');
data = reshape(data(1:end-1), 15, []).'
data.txt is attached.

カテゴリ

ヘルプ センター および File ExchangeData Import and Analysis についてさらに検索

質問済み:

2020 年 11 月 2 日

回答済み:

2020 年 11 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by