Path: news.mathworks.com!not-for-mail
From: "us " <us@neurol.unizh.ch>
Newsgroups: comp.soft-sys.matlab
Subject: Reading data into matlab
Date: Fri, 27 Jul 2007 15:43:20 +0000 (UTC)
Organization: Universit&#228;tsSpital Z&#252;rich
Lines: 44
Message-ID: <f8d3qo$6ov$1@fred.mathworks.com>
References: <f8b7sr$gbt$1@fred.mathworks.com> <f8bjea$jnq$1@fred.mathworks.com> <f8bko6$a7o$1@fred.mathworks.com>
Reply-To: "us " <us@neurol.unizh.ch>
NNTP-Posting-Host: webapp-01-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1185551000 6943 172.30.248.36 (27 Jul 2007 15:43:20 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 27 Jul 2007 15:43:20 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 11
Xref: news.mathworks.com comp.soft-sys.matlab:421418


Felipe Sediles:
<SNIP data import evergreen...

> The answer to your question is yes, with one qualifier: there is another, separate, block of data that is formated in this way within the same file.  I'd like to read this block of data as well, separately, though...

one of the solutions is outlined below

% 1) assume this context in a file <foo.txt>
Heading
Node
1, -31.750000000, 0.000000000, 3.174999960
2, -31.750000000, 5.800000200, 3.174999960
*Heading
*Node
10, -31.750000000, 0.000000000, 3.174999960
20, -31.750000000, 5.800000200, 3.174999960
30, -31.750000000, 5.800000200, 3.174999960
this is a test end
300 40 50 60
400,

% the engine
     fnam='foo.txt'; % <- your file!
     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 
     ixn=cellfun('isempty',an(:,3)); 
     ixs=cellfun(@(x) x==4,an(:,2)); 
     ib=strfind(ixs.',[0,1])+1;
     ie=strfind(ixs.',[1,0]);
if   ~isempty(ib)
     nb=numel(ib);
     rb=cell(nb,1);
for  i=1:nb
     rb{i,1}=reshape(cat(1,an{ib(i):ie(i),1}).',4,[]).';
end
end
% the result 
     type(fnam);
     rb{:}

us