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일
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 Exchange에서 Data 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