Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: about textread
Date: Mon, 2 Jun 2008 09:14:03 +0000 (UTC)
Organization: Pierburg GmbH
Lines: 57
Message-ID: <g20dkr$aof$1@fred.mathworks.com>
References: <fu4tt6$rjq$1@fred.mathworks.com> <fu8ahh$c8m$1@fred.mathworks.com> <g1u9v6$2i4$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1212398043 11023 172.30.248.35 (2 Jun 2008 09:14:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 2 Jun 2008 09:14:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 872224
Xref: news.mathworks.com comp.soft-sys.matlab:471733



"Wu Zhiyong" <wuzhiyong_163@163.com> wrote in message 
<g1u9v6$2i4$1@fred.mathworks.com>...
> But one more question:
>   How can I ignore the blank line?
> for example:
> airpressure staions  bias      MAE     RMSE    HR
>  300.0        38   1.55661   1.83753  2.44242  26
> 
> airpressure staions  bias      MAE     RMSE    HR
>  200.0       44   1.82511   2.34681  2.78835  22
> ........

I'm currently thinking about an enhancement of txt2mat 
which would involve allowing to completely ignore empty 
lines (this would even imply speed benefits). With the 
current version on the fex, you'll need some kind of trick 
to remove them (see below). 
 
Just for the sake of completeness: The standard method 
would be to directly switch to ReadMode 'line' and sort out 
the NaN rows afterwards:
 
fn = 'c:\myfile.txt'
 
A = txt2mat(fn,0,6,'BadLineString', ...
            {'air'},'ReadMode','line');
A = A(isfinite(A(:,1)), :);
 
Use the 'InfoLevel' parameter to suppress the command line 
information about the different row lengths, if you like 
(see help).
 
Now for the 'trick':
To remove the empty lines in the text, you can also delete 
consecutive line break characters by the help of 
the 'ReplaceExpr'. On a windows system (!), the character 
pair char([13 10]) forms a single line break. If your empty 
lines do not contain any whitespace, the occurence of 
char([10 13]) indicates a double line break. Hence, use
 
B = txt2mat(fn,0,6,'BadLineString',{'air'},...
            'ReplaceExpr',{{char([10, 13]),''}});
 
Usually, txt2mat expects anything to be manipulated with 
the exception of line breaks. As txt2mat cycles throught 
the text by sections containing 200'000 lines by default, 
the above will only work safely if you have less data lines 
+ empty lines than that. Of course, you could get around 
that as well (see 'MemPar' argument). If you need further 
information, feel free to contact me via the fex form. 
Please check which solution is most convenient in terms of 
usage and speed on your system.
 
Hth,
regards
Andres