Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
extracting .tar files and reading .txt data

Subject: extracting .tar files and reading .txt data

From: Rogelio

Date: 9 Jun, 2012 21:47:06

Message: 1 of 3

I have the following problem: I want to download a tar file and extract the data into matlab. But I cannot extract the data! I have the following code but doesnt do the work.

url = 'http://prep2009.ife.org.mx/PREP2009/20090706_2000-listaActas.tar.gz';
file = untar(url);
fid=fopen('diputados.txt');
C_text=textscan(fid,'%s',25,'delimiter','|');
C_data=textscan(fid,'%d %d %d %s %d %d %d %d %d %d %d %d %d %d %s %d %d %d %d %d %s %d %s %s %s','delimiter','|');

The text file has originally 6 header lines but I deleted them before using the above lines to make it easier.

Any suggestion is appreciated.

Subject: extracting .tar files and reading .txt data

From: Steven_Lord

Date: 11 Jun, 2012 14:22:43

Message: 2 of 3



"Rogelio " <rogelioa.deletethis@math.uio.no> wrote in message
news:jr0g8q$62n$1@newscl01ah.mathworks.com...
> I have the following problem: I want to download a tar file and extract
> the data into matlab. But I cannot extract the data! I have the following
> code but doesnt do the work.
>
> url =
> 'http://prep2009.ife.org.mx/PREP2009/20090706_2000-listaActas.tar.gz';
> file = untar(url);
> fid=fopen('diputados.txt');
> C_text=textscan(fid,'%s',25,'delimiter','|');
> C_data=textscan(fid,'%d %d %d %s %d %d %d %d %d %d %d %d %d %d %s %d %d %d
> %d %d %s %d %s %s %s','delimiter','|');

Define "doesnt[sic] do the work" -- did it throw an error (and if so what is
the full text of the error message?) Did it throw a warning (ditto on the
full text?) Did it give you results you didn't expect?

Show the group a SMALL sample of the file disputados.txt and the results you
received from trying to read it with that code.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: extracting .tar files and reading .txt data

From: Rogelio

Date: 12 Jun, 2012 21:04:15

Message: 3 of 3

"Steven_Lord" <slord@mathworks.com> wrote in message <jr4uvj$ade$1@newscl01ah.mathworks.com>...
>
>
> "Rogelio " <rogelioa.deletethis@math.uio.no> wrote in message
> news:jr0g8q$62n$1@newscl01ah.mathworks.com...
> > I have the following problem: I want to download a tar file and extract
> > the data into matlab. But I cannot extract the data! I have the following
> > code but doesnt do the work.
> >
> > url =
> > 'http://prep2009.ife.org.mx/PREP2009/20090706_2000-listaActas.tar.gz';
> > file = untar(url);
> > fid=fopen('diputados.txt');
> > C_text=textscan(fid,'%s',25,'delimiter','|');
> > C_data=textscan(fid,'%d %d %d %s %d %d %d %d %d %d %d %d %d %d %s %d %d %d
> > %d %d %s %d %s %s %s','delimiter','|');
>
> Define "doesnt[sic] do the work" -- did it throw an error (and if so what is
> the full text of the error message?) Did it throw a warning (ditto on the
> full text?) Did it give you results you didn't expect?
>
> Show the group a SMALL sample of the file disputados.txt and the results you
> received from trying to read it with that code.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

I found the problem! "textscan" stops scanning the text file when it occurs a problem, such as type mismatch. In my text file some columns includes integers and strings so if I specify the column as integer, i.e. %d, when the first string appears then "textscan" stops. I manage to read all the file by specifying the whole column as string and then I transform it as I need it.
Thanks !

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us