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'}

Answers (1)

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.

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Asked:

on 2 Nov 2020

Answered:

on 2 Nov 2020

Community Treasure Hunt

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

Start Hunting!