How To Convert data separated by commas into columns.
Afficher commentaires plus anciens
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'}
Réponses (1)
Ameer Hamza
le 2 Nov 2020
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.
Catégories
En savoir plus sur Data Import and Analysis dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!