<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/173648</link>
    <title>MATLAB Central Newsreader - Delete single line using textscan</title>
    <description>Feed for thread: Delete single line using textscan</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Fri, 01 Aug 2008 20:41:03 -0400</pubDate>
      <title>Delete single line using textscan</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/173648#446848</link>
      <author>David Reed</author>
      <description>I want to use textscan to bring in a whole bunch of data,&lt;br&gt;
almost 50000 lines of it.  Everything is formatted nicely&lt;br&gt;
except for a few lines here and there.  &lt;br&gt;
&lt;br&gt;
I need a way for text scan to not read these lines.  The&lt;br&gt;
problem is that they start like the others so I can't use&lt;br&gt;
commentstyle.  &lt;br&gt;
&lt;br&gt;
Does anyone have any ideas.  Thanks</description>
    </item>
    <item>
      <pubDate>Fri, 01 Aug 2008 20:54:12 -0400</pubDate>
      <title>Re: Delete single line using textscan</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/173648#446851</link>
      <author>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)</author>
      <description>In article &amp;lt;g6vscv$91j$1@fred.mathworks.com&amp;gt;,&lt;br&gt;
David Reed &amp;lt;dreed@mitre.org&amp;gt; wrote:&lt;br&gt;
&amp;gt;I want to use textscan to bring in a whole bunch of data,&lt;br&gt;
&amp;gt;almost 50000 lines of it.  Everything is formatted nicely&lt;br&gt;
&amp;gt;except for a few lines here and there.  &lt;br&gt;
&lt;br&gt;
&amp;gt;I need a way for text scan to not read these lines.  The&lt;br&gt;
&amp;gt;problem is that they start like the others so I can't use&lt;br&gt;
&amp;gt;commentstyle.  &lt;br&gt;
&lt;br&gt;
&amp;gt;Does anyone have any ideas.  Thanks&lt;br&gt;
&lt;br&gt;
If you know exact line numbers, use counts on the textscan()&lt;br&gt;
to read up to that point, then fgetl() to read the next&lt;br&gt;
line (and discard it), then textscan() as much more as you can, etc..&lt;br&gt;
&lt;br&gt;
If you don't know exact line numbers and can only tell by the&lt;br&gt;
different formatting, you can either process a line at a time&lt;br&gt;
(using fgetl to get the line and then one of the several parsing&lt;br&gt;
routines), or you can read the entire file at once as a string,&lt;br&gt;
delete the lines that give the problems, then textscan() the&lt;br&gt;
string variable. (You can put a string in, in place of a fid).&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&quot;I was very young in those days, but I was also rather dim.&quot;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;-- Christopher Priest</description>
    </item>
    <item>
      <pubDate>Sat, 02 Aug 2008 07:32:39 -0400</pubDate>
      <title>Re: Delete single line using textscan</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/173648#446904</link>
      <author>AHMET ANIL DINDAR</author>
      <description>Hi,&lt;br&gt;
I've a nice script for evaulation of such files.&lt;br&gt;
&lt;br&gt;
%%%--------------------- START %%%%%%%%%%&lt;br&gt;
fid=fopen('filename.dat') ; % the original file&lt;br&gt;
fidd=fopen('new filename.dat') ; % the new file&lt;br&gt;
while ~feof(fid) ; % reads the original till last line&lt;br&gt;
&amp;nbsp;&amp;nbsp;tline=fgets(fid) ; % &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if &quot;CONDITION STATEMENT THAT REPRESENTS THE LINES YOU &lt;br&gt;
&amp;nbsp;WANT TO DELETE&quot;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fprinft(fidd,tline) ;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
end&lt;br&gt;
fclose all&lt;br&gt;
%%%--------------------- END %%%%%%%%%%&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
This is a simple script lets you to evaulate each line and&lt;br&gt;
take action.&lt;br&gt;
&lt;br&gt;
Ahmet Anil Dindar</description>
    </item>
    <item>
      <pubDate>Sat, 02 Aug 2008 07:45:03 -0400</pubDate>
      <title>Re: Delete single line using textscan</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/173648#446905</link>
      <author>AHMET ANIL DINDAR</author>
      <description>Correction to my code&lt;br&gt;
say the file (ahmet.txt) includes the following lines &lt;br&gt;
&lt;br&gt;
ahmet an&amp;#305;l dindar&lt;br&gt;
10 20 30 40 &lt;br&gt;
10 20 30 40 &lt;br&gt;
10 20 30 40 &lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
the script for deletion the alphabetic lines is &lt;br&gt;
&lt;br&gt;
%%%--------------------- START %%%%%%%%%%&lt;br&gt;
fid=fopen('ahmet.txt') ; % the original file&lt;br&gt;
fidd=fopen('new filename.dat','w') ; % the new file&lt;br&gt;
while ~feof(fid) ; % reads the original till last line&lt;br&gt;
&amp;nbsp;&amp;nbsp;tline=fgets(fid) ;  % &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if isletter(tline(1))==1 ;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fwrite(fidd,tline) ;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
end&lt;br&gt;
fclose all ;&lt;br&gt;
%%% -------------------END %%%%%%%%%%%%%%&lt;br&gt;
&lt;br&gt;
the new file includes&lt;br&gt;
&lt;br&gt;
10 20 30 40 &lt;br&gt;
10 20 30 40 &lt;br&gt;
10 20 30 40 &lt;br&gt;
&lt;br&gt;
I tested it and it worked.&lt;br&gt;
&lt;br&gt;
AAD</description>
    </item>
    <item>
      <pubDate>Sat, 02 Aug 2008 10:15:05 -0400</pubDate>
      <title>Re: Delete single line using textscan</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/173648#446914</link>
      <author>Andres </author>
      <description>&quot;David Reed&quot; &amp;lt;dreed@mitre.org&amp;gt; wrote in message&lt;br&gt;
&amp;lt;g6vscv$91j$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I want to use textscan to bring in a whole bunch of data,&lt;br&gt;
&amp;gt; almost 50000 lines of it.  Everything is formatted nicely&lt;br&gt;
&amp;gt; except for a few lines here and there.  &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I need a way for text scan to not read these lines.  The&lt;br&gt;
&amp;gt; problem is that they start like the others so I can't use&lt;br&gt;
&amp;gt; commentstyle.  &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Does anyone have any ideas.  Thanks&lt;br&gt;
&lt;br&gt;
I don't know if this applies to your problem, but just as a&lt;br&gt;
hint:&lt;br&gt;
txt2mat from the file exchange has the option to ignore&lt;br&gt;
lines in the text file that can be identified by one or more&lt;br&gt;
distinct strings ('BadLineString', see the doc). It can also&lt;br&gt;
import the whole file line-by-line, letting you sort out the&lt;br&gt;
critical lines afterwards. Note that it is made for an&lt;br&gt;
import of data resulting in a single numeric matrix. If you&lt;br&gt;
need advice with txt2mat, you may contact me (the author)&lt;br&gt;
via the file exchange 'Contact author' button.&lt;br&gt;
Regards&lt;br&gt;
Andres</description>
    </item>
    <item>
      <pubDate>Wed, 24 Sep 2008 02:19:01 -0400</pubDate>
      <title>Re: Delete single line using textscan</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/173648#601776</link>
      <author>Cy abd</author>
      <description>&quot;AHMET ANIL DINDAR&quot; &amp;lt;adindar@iku.edu.tr&amp;gt; wrote in message &amp;lt;g7139v$8mp$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Correction to my code&lt;br&gt;
&amp;gt; say the file (ahmet.txt) includes the following lines &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; ahmet an&amp;#305;l dindar&lt;br&gt;
&amp;gt; 10 20 30 40 &lt;br&gt;
&amp;gt; 10 20 30 40 &lt;br&gt;
&amp;gt; 10 20 30 40 &lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; the script for deletion the alphabetic lines is &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; %%%--------------------- START %%%%%%%%%%&lt;br&gt;
&amp;gt; fid=fopen('ahmet.txt') ; % the original file&lt;br&gt;
&amp;gt; fidd=fopen('new filename.dat','w') ; % the new file&lt;br&gt;
&amp;gt; while ~feof(fid) ; % reads the original till last line&lt;br&gt;
&amp;gt;   tline=fgets(fid) ;  % &lt;br&gt;
&amp;gt;      if isletter(tline(1))==1 ;&lt;br&gt;
&amp;gt;      else&lt;br&gt;
&amp;gt;        fwrite(fidd,tline) ;&lt;br&gt;
&amp;gt;      end&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; fclose all ;&lt;br&gt;
&amp;gt; %%% -------------------END %%%%%%%%%%%%%%&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; the new file includes&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 10 20 30 40 &lt;br&gt;
&amp;gt; 10 20 30 40 &lt;br&gt;
&amp;gt; 10 20 30 40 &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I tested it and it worked.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; AAD&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
AAD,&lt;br&gt;
GREAT JOB, thank you. This is exactly what I was looking for.</description>
    </item>
  </channel>
</rss>

