Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: textread - recall last position
Date: Wed, 11 Feb 2009 19:40:17 +0000 (UTC)
Organization: Universit&#228;tsSpital Z&#252;rich
Lines: 27
Message-ID: <gmv9j1$i80$1@fred.mathworks.com>
References: <dc52385c-cfea-4944-b563-bcc8c1a9a27c@g1g2000pra.googlegroups.com>
Reply-To: <HIDDEN>
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 1234381217 18688 172.30.248.37 (11 Feb 2009 19:40:17 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 11 Feb 2009 19:40:17 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 11
Xref: news.mathworks.com comp.soft-sys.matlab:517697


supandey@yahoo.com
> %test
> 10,20,30
> 40,50,60
> I can read via:
> [x1,x2,x3] = textread('t.txt','%d%d%d',
> 1,'delimiter',',','commentstyle','matlab');
> [y1,y2,y3] = textread('t.txt','%d%d%d',
> 1,'delimiter',',','commentstyle','matlab', 'headerlines', 2);
> 
> Is there another solution which avoids using headerlines...

one of the solutions

     fnam='t.txt'; % <- your text file...
     s=textread(fnam,'%s','delimiter','\n');
     d=cellfun(@(x) sscanf(x,'%g,').',s(2:end),'uni',false);
     d{1:2} % <- or d{:}
%{
%    ans =
          10    20    30
%    ans =
          40    50    60
%}
% it comes with the benefit of NOT having too many vars in your ws...

us