How to define the range for reading a csv file

5 visualizaciones (últimos 30 días)
papafos
papafos el 14 de Abr. de 2014
Comentada: papafos el 4 de Mayo de 2014
Hello,
I have the following problem.I have a batch of .csv files that have the following format:
[10 rows of text data]
[useful numerical data varying number of rows x 40colums]
[10 rows of text data always starting with the specific word "ACP"]
[useful numerical data varying number of rows x 40colums]
What I need to do is to focus only to the numerical data. So,I need a way to detect for every fileat which point starts the second part of the text data and neglect it.In other words,I want to find the range of the first and the second part of the numerical data.
Thanks in advance.

Respuestas (2)

Image Analyst
Image Analyst el 14 de Abr. de 2014
I think that second batch of text lines in between the numerical data is what ruins it for you and prevents you from using functions like csvread(), readtable(), or importdata(). So I think you'll have to make a little custom routine to go through it line by line with textscan() or fgetl() and sscanf() to extract the data only when your line does not start with ACP. Use strfind() to see if ACP is on each line.

Alberto
Alberto el 14 de Abr. de 2014
The problem here is that you can't predict how many rows the numerical data will have.
I recommend extract all using a generic command, like textscan for example, and then try to convert the types you get to numeric. If it can be done, that will be your desired data; if cannot then its textdata so it can be ignored.
  3 comentarios
Alberto
Alberto el 14 de Abr. de 2014
You are right, the problem with the first block is we don't know when to stop scanning before text.
papafos
papafos el 4 de Mayo de 2014
I finally found a way to isolate the first and the second set of data. I used both importadata() and textscan() and took into account some conditions that hold for all the files regarding the rows of the second part of text. Thank you for the response.

Iniciar sesión para comentar.

Categorías

Más información sobre Text Data Preparation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by