Path: news.mathworks.com!not-for-mail
From: "Felipe Sediles" <felipe.sediles.nospam@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Reading data into matlab
Date: Fri, 27 Jul 2007 16:17:20 +0000 (UTC)
Organization: Syracuse University
Lines: 53
Message-ID: <f8d5qg$4i$1@fred.mathworks.com>
References: <f8b7sr$gbt$1@fred.mathworks.com> <f8bjea$jnq$1@fred.mathworks.com> <f8bko6$a7o$1@fred.mathworks.com> <f8d3qo$6ov$1@fred.mathworks.com>
Reply-To: "Felipe Sediles" <felipe.sediles.nospam@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 1185553040 146 172.30.248.35 (27 Jul 2007 16:17:20 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 27 Jul 2007 16:17:20 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1066294
Xref: news.mathworks.com comp.soft-sys.matlab:421433


"us " <us@neurol.unizh.ch> wrote in message <f8d3qo$6ov$1@fred.mathworks.com>...
> 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
Thanks!  I just ran it and I get:

??? Function name must be a string.

Error in ==> data_read at 9
     ixs=cellfun(@(x) x==4,an(:,2));

I've familiar with cellfun so I couldn't figure out how to solve this.