Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to remove unwanted text from a .txt file?
Date: Wed, 24 Sep 2008 05:31:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 29
Message-ID: <gbcjal$h84$1@fred.mathworks.com>
References: <gbbqun$qo5$1@fred.mathworks.com> <ryeCk.36464$QF5.28064@newsfe08.iad> <gbbubd$2n7$1@fred.mathworks.com> <VGfCk.562$Cl1.66@newsfe01.iad> <gbc1vn$8k6$1@fred.mathworks.com> <gbc2m6$de7$1@fred.mathworks.com> <gbc4i6$qf5$1@fred.mathworks.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 1222234261 17668 172.30.248.37 (24 Sep 2008 05:31:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 24 Sep 2008 05:31:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1248302
Xref: news.mathworks.com comp.soft-sys.matlab:491713


The following code does what I need to do but is very slow since the .txt file is about 500,000 lines and the 3rd. line after else takes up 85% of the total time! How can that line be optimized please?

// the line consuming the most time 85%.
B(r,:) = [data1 data2 data3 data4 data5 data6 data7];


// the complete code:
r=1;
fid=fopen('Test.txt') ; 
while ~feof(fid) ; 
  tline=fgets(fid) ; 
     if isletter(tline(1))==1 ;
     else
        A = textscan(tline,'%f %f %f %f %f %f %f','delimiter',',');
        [data1 data2 data3 data4 data5 data6 data7] = A{:};
        B(r,:) = [data1 data2 data3 data4 data5 data6 data7];
        r=r+1;
     end
end
fclose all ;


// sample text from the 'Test.txt' average 10 Meg.!:

13,14,02,1212.75,332,11
13,14,02,1212.75,374,11
13,14,03,1212.75,5,22
13,14,03,1212.75,5,22