How to read mixed delimited data from a text file?

3 visualizaciones (últimos 30 días)
Aimee Coleman
Aimee Coleman el 25 de Abr. de 2019
Respondida: dpb el 25 de Abr. de 2019
I have a text file with a mix of delimiters, tabs and spaces and returns on some of the data. How do I read the data left to right and top to bottom and store them as a single column of datapoints?
The data in the text file looks like this:
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
(in-between the datapoints there are 4 spaces and one tab)
I'd like to read the data: '1, 2, 3, 4, 5, 6, ....' and then export it to another text file as just a single column.
It's probably fairly basic, but can anyone help me out?
  2 comentarios
Bob Thompson
Bob Thompson el 25 de Abr. de 2019
By mixed delimiters, do you mean varying amounts of white space, or that there are different symbols for delimiters? (I.e. a comma, then a semi-colon, etc.)
Aimee Coleman
Aimee Coleman el 25 de Abr. de 2019
Varying amounts of white space using both tabs and standard spaces as well as having 5 numbers per row, effectively making 5 columns, each of which is separated by 4 spaces and 1 tab.

Iniciar sesión para comentar.

Respuestas (1)

dpb
dpb el 25 de Abr. de 2019
If the file is tab-delimited, the spaces won't matter...
data=dlmread(fullfile('yourdirectory','yourfile.txt'),'\t'); % read tab-delimited file
data=data(:); % ML idiom to convert array to column vector
dlmwrite(fullfile('yourdirectory','yourNEWfile.txt')) % write a new text file

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by