Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!r15g2000prh.googlegroups.com!not-for-mail
From: NZTideMan <mulgor@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: ascii import
Date: Mon, 10 Nov 2008 12:24:14 -0800 (PST)
Organization: http://groups.google.com
Lines: 65
Message-ID: <e80b7023-7d1f-43f6-a808-880e2dce8c1a@r15g2000prh.googlegroups.com>
References: <gfa27i$kr6$1@fred.mathworks.com>
NNTP-Posting-Host: 202.78.152.105
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1226348654 21886 127.0.0.1 (10 Nov 2008 20:24:14 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Mon, 10 Nov 2008 20:24:14 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: r15g2000prh.googlegroups.com; posting-host=202.78.152.105; 
	posting-account=qPexFwkAAABOl8VUndE6Jm-9Z5z_fSpR
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon; 
	Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 
	1.1.4322),gzip(gfe),gzip(gfe)
X-HTTP-Via: 1.1 nc2 (NetCache NetApp/6.0.5P1)
Xref: news.mathworks.com comp.soft-sys.matlab:500067


On Nov 11, 8:32=A0am, "Zahra" <zahra.yam...@nrc.gc.ca> wrote:
> Hi all,
>
> Can any one help for the following:
>
> I need to import data from an ascii file. The file includes different dat=
a runs that are separated by a header (the text of the header changes from =
one run to the next but the number of header lines remain the same for diff=
erent runs). Then each run has the same number of data points. The only pro=
blem is that for each data point, the data is given in two lines (there is =
a line folding) starting with the point number in the run. Here is an examp=
le of the data file, lets assume there are two runs in it and each run has =
two points:
> --------------------------------
> Run =A0 1 =A0
> header line 1
> header line 2
> Point1 =A0 v1 =A0 v2 =A0 v3 =A0 v4
> Point1 =A0 v5 =A0 v6
> Point2 =A0 v1' =A0 v2' =A0 v3' =A0 v4'
> Point2 =A0 v5' =A0 v6'
>
> Run =A02 =A0
> header line 1
> header line 2
> Point1 =A0 vv1 =A0 vv2 =A0 vv3 =A0 vv4
> Point1 =A0 vv5 =A0 vv6
> Point2 =A0 vv1' =A0 vv2' =A0 vv3' =A0 vv4'
> Point2 =A0 vv5' =A0 vv6'
> -------------------------------------------
> and so on...
>
> What I need is to remove all the header lines and have a matrix that each=
 of its rows represents a data point and its column are the data values, i.=
e. the rows of the final matrix need to be in the following format:
>
> row 1=3D[Point1 =A0 v1 =A0 v2 =A0 v3 =A0 v4 =A0 v5 =A0 v6]
> row 2=3D[Point2 =A0 v1' =A0 v2' =A0 v3' =A0 v4' =A0 v5' =A0 v6']
> row 3=3D[Point1 =A0 vv1 =A0 vv2 =A0 vv3 =A0 vv4 =A0 vv5 =A0 vv6]
> row 4=3D[Point2 =A0 vv1' =A0 vv2' =A0 vv3' =A0 vv4' =A0 vv5' =A0 vv6']
>
> I have tried different options in txt2mat, but with each option there is =
one problem or another.
>
> Can any one help?
>
> Thanks,
> Zahra

I'm not familiar with txt2mat, but this is what I'd do:

fid=3Dfopen(txtfile,'rt');
A=3Dzeros(16,nruns);     % Allocate storage for the data
for irun=3D1:nruns    % Loop thru the runs
  Run{irun}=3Dfgetl(fid);
  header1{irun}=3Dfgetl(fid);
  header2{irun}=3Dfgetl(fid);
  A(:,irun)=3Dfscanf(fid,'%f',16);   % read in the 16 data from each run
  dum=3Dfgetl(fid);    % read in blank line and discard
end
fclose(fid);

Now you have to manipulate A into the form you want by eliminating
unnecessary rows, then transposing and reshaping.