Path: news.mathworks.com!not-for-mail
From: "Pekka " <pekka.nospam.kumpulainen@tut.please.fi>
Newsgroups: comp.soft-sys.matlab
Subject: Re: how to read text file row/column info
Date: Sat, 15 Mar 2008 09:51:04 +0000 (UTC)
Organization: Tampere University of Technology
Lines: 34
Message-ID: <frg668$im6$1@fred.mathworks.com>
References: <frfjcc$it5$1@fred.mathworks.com>
Reply-To: "Pekka " <pekka.nospam.kumpulainen@tut.please.fi>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1205574664 19142 172.30.248.37 (15 Mar 2008 09:51:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 15 Mar 2008 09:51:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 218565
Xref: news.mathworks.com comp.soft-sys.matlab:457370



"Bruce Eddy" <sailboats@cfl.rr.com> wrote in message 
<frfjcc$it5$1@fred.mathworks.com>...
> Hi,
> I am trying to read a large .txt file with 5 columns and 
> over 12000 rows of data.  I'm having trouble getting the 
> (row, column) numbers right.  The code looks like this;
> 
> loop = 0;
> for i = 1:2
>     line1 = fgets(fid);
> end
> while feof(fid) == 0
>     loop = loop+1;
>     line1 = fgets(fid);
>     mass_prop(loop).name = line1(1, 1: 66);
>     mass_prop(loop).matl = line1(1,67: 102);
>     mass_prop(loop).volm = line1(1,103: 119);
>     mass_prop(loop).dens = line1(1,120:133);
>     mass_prop(loop).wght = line1(1,134:149);
> end
> 
> Can anyone help?
> Thanks.

Really hard to help much without knowing the structure of 
your file. Hard coding the indexing is generally not a good 
idea. That will fail if any of the lines has different 
length in any of the fields.

Take a look at 
doc textscan 
that should read the entire file wthout loops and hard 
coded indexing.