Path: news.mathworks.com!not-for-mail
From: "Dimitar Dimitrov" <mail_mitko@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: reading data from a tex file
Date: Tue, 31 Jul 2007 18:02:58 +0000 (UTC)
Organization: Tohoku Univ
Lines: 50
Message-ID: <f8ntgi$6bt$1@fred.mathworks.com>
References: <f8nlm1$ah7$1@fred.mathworks.com> <f8nmji$rcb$1@fred.mathworks.com>
Reply-To: "Dimitar Dimitrov" <mail_mitko@mathworks.com>
NNTP-Posting-Host: webapp-00-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1185904978 6525 172.30.248.35 (31 Jul 2007 18:02:58 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 31 Jul 2007 18:02:58 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 64454
Xref: news.mathworks.com comp.soft-sys.matlab:421899


"us " <us@neurol.unizh.ch> wrote in message <f8nmji$rcb$1@fred.mathworks.com>...
> Dimitar Dimitrov:
> <SNIP yet another data import evergreen...
> 
> one of the solutions is outlined below
> 
> % contents of file <foo.txt>
> % J1 J2
> 1 2
> 3 4
> 5 6
> 7 8
> % J1 J2 J3
> 1 2 3
> 4 5 6
> 7 8 9
> 
> % the engine
>      fnam=foo.txt';
>      a=textread(fnam,'%s','delimiter','','whitespace','');
>      an=cell(numel(a),1); 
> for i=1:numel(a) 
>      [an{i,1:3}]=sscanf(a{i},'%f'); 
> end 
>      ixs=[0,cellfun(@isempty,an(:,3)).',0];
>      ib=strfind(ixs,[0,1]);
>      ie=strfind(ixs,[1,0])-1;
> if   ~isempty(ib)
>      nb=numel(ib);
>      rb=cell(nb,1);
> for  i=1:nb
>      nc=an{ib(i),2};
>      rb{i,1}=reshape(cat(1,an{ib(i):ie(i),1}).',nc,[]).';
> end
> end
> % the result 
>      type(fnam);
>      rb{:}
> 
> us

"us", 
Thank you for the prompt reply!
This solves the problem.

Dimitar