Path: news.mathworks.com!not-for-mail
From: "us " <us@neurol.unizh.ch>
Newsgroups: comp.soft-sys.matlab
Subject: Re: seperating numbers from a cell array
Date: Tue, 31 Jul 2007 11:55:45 +0000 (UTC)
Organization: Universit&#228;tsSpital Z&#252;rich
Lines: 34
Message-ID: <f8n801$343$1@fred.mathworks.com>
References: <f8kh7u$dll$1@fred.mathworks.com> <1185795493.093689.11280@o61g2000hsh.googlegroups.com> <f8n597$dp0$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 1185882945 3203 172.30.248.36 (31 Jul 2007 11:55:45 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 31 Jul 2007 11:55:45 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 11
Xref: news.mathworks.com comp.soft-sys.matlab:421838


Sachitha Obeysekara:
<SNIP down to gruesome ML atrocity...

> here's what i'm using:
> regEx = '%s';
> for i = 1:(numFieldsOut-1)
>     regEx = [regEx '%n'];
> end
> b=textscan(b,regEx,'delimiter',',');
> output = '[';
> for i = 2:numFieldsOut
>     output = [output 'b{1,' num2str(i) '} '];  
> end
> output = [output ']'];
> output = eval(output);

WHY not simply use what you were given above?!...

% some data
     b={
          'T1,1,20,300,4000,00256.964'
          'T10,1,20,300,4000,00356.964'
          'TT1,10,200,3000,40000,00456'
     };
     nf=5; % #floats...
% the engine
     fmt=['%s',repmat('%f',1,nf)];
     r=textscan(char(b).',fmt,'delimiter',',');
     r=cat(2,r{:,2:end});
% the result
     b
     r

us