Reading data from csv with non uniform formatting

Hi,
I am trying to read data from a cvs file (sample attached) with uneven formatting where there are a few sentences and lines with missing data points. I have been reading the file and then getting the row number for each time the column with is different to extract the data. I am trying to read ( and remove) the sentences and also remove the partially complete rows and creating one array from the remaining data. Is there any better way of doing this withouth having to check which row is incomplete? Any suggestions would be very helpful.
Thank you

5 comentarios

It's a little unclear to me what the final result should be from the sample file you have shared. Is this the expectation?
A,1,2,3,4
B,1,2,3,4
C,1,2,3,4
D,1,2,3,4
A,1,2,3,4
B,1,2,3,4
C,1,2,3,4
A,1,2,3,4
D,1,2,3,4
C,1,2,3,4
E,1,2,3,4
AG15
AG15 el 24 de Abr. de 2023
Thanks a lot for the help, that is the intention to remove the rows. I have been using textscan to scan the document. Would you recommend moving to readtable instead?
Stephen23
Stephen23 el 24 de Abr. de 2023
"Would you recommend moving to readtable instead? "
Yes.
AG15
AG15 el 24 de Abr. de 2023
Thank you
Yes. If you are new to tables, see this page on how to access data in tables.

Iniciar sesión para comentar.

 Respuesta aceptada

I would use readtable with the settings to 'omitrow' when data is missing.
T = readtable('sample.csv','MissingRule','omitrow')
T = 11×5 table
Var1 Var2 Var3 Var4 Var5 _____ ____ ____ ____ ____ {'A'} 1 2 3 4 {'B'} 1 2 3 4 {'C'} 1 2 3 4 {'D'} 1 2 3 4 {'A'} 1 2 3 4 {'B'} 1 2 3 4 {'C'} 1 2 3 4 {'A'} 1 2 3 4 {'D'} 1 2 3 4 {'C'} 1 2 3 4 {'E'} 1 2 3 4

Más respuestas (0)

Productos

Versión

R2022b

Etiquetas

Preguntada:

el 24 de Abr. de 2023

Comentada:

el 24 de Abr. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by