<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172022</link>
    <title>MATLAB Central Newsreader - Text file with numbers and text, want to just read numbers</title>
    <description>Feed for thread: Text file with numbers and text, want to just read numbers</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>Thu, 03 Jul 2008 20:18:01 -0400</pubDate>
      <title>Text file with numbers and text, want to just read numbers</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172022#441093</link>
      <author>Matt </author>
      <description>I have a series of text files I want to read.  The files &lt;br&gt;
begin with header information.  The number of rows of &lt;br&gt;
header information changes, there is no commenting symbol &lt;br&gt;
such as %%, and the header information sometimes has &lt;br&gt;
numbers such as a date or a time.  I want to read in the &lt;br&gt;
number and only the numbers.  &lt;br&gt;
&lt;br&gt;
This is an example of a file: (Again, the header info &lt;br&gt;
changes, different # of lines, different text)&lt;br&gt;
&lt;br&gt;
Vector Signal [Measurement4]:  09/27/2006, 09:05:24&lt;br&gt;
Units: EU&lt;br&gt;
Time	 Real&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0	      0.053732&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;9.6e-005	       0.11968&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.000192	      0.085483&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.000288	       0.11968&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.000384	       0.18562&lt;br&gt;
&lt;br&gt;
Currently I have Matlab code something like this:&lt;br&gt;
&lt;br&gt;
[filename, pathname, filterindex] = uigetfile&lt;br&gt;
({'*.txt','Text file (*.txt)';'*.*','All Files &lt;br&gt;
(*.*)'},'Pick Time History File');&lt;br&gt;
fid = fopen(filename);&lt;br&gt;
C_text = textscan(fid,'%s');&lt;br&gt;
fclose(fid);&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
I tried to sort out the header from C_text by creating a &lt;br&gt;
loop searching for numbers.  Example, seeing if the &lt;br&gt;
absolute value is greater than one.  This method failed &lt;br&gt;
when it ran into dates and times.  &lt;br&gt;
&lt;br&gt;
Is there a better way?  I've been trying to use textscan, &lt;br&gt;
but I have also been looking at fscan and textread.  I &lt;br&gt;
think there may be some formatting with C_text that could &lt;br&gt;
work, but I couldn't get it to work.  </description>
    </item>
    <item>
      <pubDate>Fri, 04 Jul 2008 06:55:06 -0400</pubDate>
      <title>Re: Text file with numbers and text, want to just read numbers</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172022#441130</link>
      <author>Paul </author>
      <description>&quot;Matt &quot; &amp;lt;matthew.r.duncan@boeing.com&amp;gt; wrote in message&lt;br&gt;
&amp;lt;g4jc5p$341$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I have a series of text files I want to read.  The files &lt;br&gt;
&amp;gt; begin with header information.  The number of rows of &lt;br&gt;
&amp;gt; header information changes, there is no commenting symbol &lt;br&gt;
&amp;gt; such as %%, and the header information sometimes has &lt;br&gt;
&amp;gt; numbers such as a date or a time.  I want to read in the &lt;br&gt;
&amp;gt; number and only the numbers.  &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; This is an example of a file: (Again, the header info &lt;br&gt;
&amp;gt; changes, different # of lines, different text)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Vector Signal [Measurement4]:  09/27/2006, 09:05:24&lt;br&gt;
&amp;gt; Units: EU&lt;br&gt;
&amp;gt; Time	 Real&lt;br&gt;
&amp;gt;             0	      0.053732&lt;br&gt;
&amp;gt;      9.6e-005	       0.11968&lt;br&gt;
&amp;gt;      0.000192	      0.085483&lt;br&gt;
&amp;gt;      0.000288	       0.11968&lt;br&gt;
&amp;gt;      0.000384	       0.18562&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Currently I have Matlab code something like this:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; [filename, pathname, filterindex] = uigetfile&lt;br&gt;
&amp;gt; ({'*.txt','Text file (*.txt)';'*.*','All Files &lt;br&gt;
&amp;gt; (*.*)'},'Pick Time History File');&lt;br&gt;
&amp;gt; fid = fopen(filename);&lt;br&gt;
&amp;gt; C_text = textscan(fid,'%s');&lt;br&gt;
&amp;gt; fclose(fid);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I tried to sort out the header from C_text by creating a &lt;br&gt;
&amp;gt; loop searching for numbers.  Example, seeing if the &lt;br&gt;
&amp;gt; absolute value is greater than one.  This method failed &lt;br&gt;
&amp;gt; when it ran into dates and times.  &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Is there a better way?  I've been trying to use textscan, &lt;br&gt;
&amp;gt; but I have also been looking at fscan and textread.  I &lt;br&gt;
&amp;gt; think there may be some formatting with C_text that could &lt;br&gt;
&amp;gt; work, but I couldn't get it to work.  &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
I would read the headers with fgetl and then decide if the&lt;br&gt;
first character is a letter, which indicates a header line&lt;br&gt;
in your example.  Once past the headers, I would then read&lt;br&gt;
the data with a textscan.</description>
    </item>
    <item>
      <pubDate>Fri, 04 Jul 2008 07:24:02 -0400</pubDate>
      <title>Re: Text file with numbers and text, want to just read numbers</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172022#441132</link>
      <author>Andres </author>
      <description>&quot;Matt &quot; &amp;lt;matthew.r.duncan@boeing.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;g4jc5p$341$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I have a series of text files I want to read.  The files &lt;br&gt;
&amp;gt; begin with header information.  The number of rows of &lt;br&gt;
&amp;gt; header information changes, there is no commenting symbol &lt;br&gt;
&amp;gt; such as %%, and the header information sometimes has &lt;br&gt;
&amp;gt; numbers such as a date or a time.  I want to read in the &lt;br&gt;
&amp;gt; number and only the numbers.  &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; This is an example of a file: (Again, the header info &lt;br&gt;
&amp;gt; changes, different # of lines, different text)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Vector Signal [Measurement4]:  09/27/2006, 09:05:24&lt;br&gt;
&amp;gt; Units: EU&lt;br&gt;
&amp;gt; Time	 Real&lt;br&gt;
&amp;gt;             0	      0.053732&lt;br&gt;
&amp;gt;      9.6e-005	       0.11968&lt;br&gt;
&amp;gt;      0.000192	      0.085483&lt;br&gt;
&amp;gt;      0.000288	       0.11968&lt;br&gt;
&amp;gt;      0.000384	       0.18562&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; [..]&lt;br&gt;
&lt;br&gt;
Hi,&lt;br&gt;
you may try txt2mat from the file exchange which heavily &lt;br&gt;
uses regular expressions to separate the header from the &lt;br&gt;
numeric data (if the user does not supply the number of &lt;br&gt;
header lines). It returns this data as a numeric matrix &lt;br&gt;
variable &quot;A&quot; and the header lines as a string &quot;hl&quot; if you &lt;br&gt;
type&lt;br&gt;
&lt;br&gt;
[A,ffn,nh,SR,hl] = txt2mat('c:\myFile.txt');&lt;br&gt;
&lt;br&gt;
You can then parse &quot;hl&quot; separately to extract additional &lt;br&gt;
numbers.&lt;br&gt;
&lt;br&gt;
Regards&lt;br&gt;
Andres</description>
    </item>
    <item>
      <pubDate>Fri, 04 Jul 2008 09:32:02 -0400</pubDate>
      <title>Re: Text file with numbers and text, want to just read numbers</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172022#441150</link>
      <author>Jos </author>
      <description>&quot;Matt &quot; &amp;lt;matthew.r.duncan@boeing.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;g4jc5p$341$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I have a series of text files I want to read.  The files &lt;br&gt;
&amp;gt; begin with header information.  The number of rows of &lt;br&gt;
&amp;gt; header information changes, there is no commenting symbol &lt;br&gt;
&amp;gt; such as %%, and the header information sometimes has &lt;br&gt;
&amp;gt; numbers such as a date or a time.  I want to read in the &lt;br&gt;
&amp;gt; number and only the numbers.  &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; This is an example of a file: (Again, the header info &lt;br&gt;
&amp;gt; changes, different # of lines, different text)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Vector Signal [Measurement4]:  09/27/2006, 09:05:24&lt;br&gt;
&amp;gt; Units: EU&lt;br&gt;
&amp;gt; Time	 Real&lt;br&gt;
&amp;gt;             0	      0.053732&lt;br&gt;
&amp;gt;      9.6e-005	       0.11968&lt;br&gt;
&amp;gt;      0.000192	      0.085483&lt;br&gt;
&amp;gt;      0.000288	       0.11968&lt;br&gt;
&amp;gt;      0.000384	       0.18562&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Currently I have Matlab code something like this:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; [filename, pathname, filterindex] = uigetfile&lt;br&gt;
&amp;gt; ({'*.txt','Text file (*.txt)';'*.*','All Files &lt;br&gt;
&amp;gt; (*.*)'},'Pick Time History File');&lt;br&gt;
&amp;gt; fid = fopen(filename);&lt;br&gt;
&amp;gt; C_text = textscan(fid,'%s');&lt;br&gt;
&amp;gt; fclose(fid);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I tried to sort out the header from C_text by creating a &lt;br&gt;
&amp;gt; loop searching for numbers.  Example, seeing if the &lt;br&gt;
&amp;gt; absolute value is greater than one.  This method failed &lt;br&gt;
&amp;gt; when it ran into dates and times.  &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Is there a better way?  I've been trying to use textscan, &lt;br&gt;
&amp;gt; but I have also been looking at fscan and textread.  I &lt;br&gt;
&amp;gt; think there may be some formatting with C_text that could &lt;br&gt;
&amp;gt; work, but I couldn't get it to work.  &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
1) read all lines using&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;s = textscan(filename,'%s','delimiter','\n') ;&lt;br&gt;
&lt;br&gt;
2) determine at which lines data starts, e.g. line X&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;This is the real problem!&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;p = regexp(s,'[A-Za-z]') will give a cell array with non-&lt;br&gt;
empty cells when a line contains text (but how to deal with &lt;br&gt;
scientific notation ...). See help regexp for more options.&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;X = max(find(~cellfun('isempty',p))) + 1&lt;br&gt;
&lt;br&gt;
3) read again skipping the first (X-1) lines:&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;data = textread(filename,'%f','headerlines',X-1) ;&lt;br&gt;
&lt;br&gt;
4) </description>
    </item>
    <item>
      <pubDate>Fri, 04 Jul 2008 10:52:01 -0400</pubDate>
      <title>Re: Text file with numbers and text, want to just read numbers</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172022#441166</link>
      <author>Andres </author>
      <description>&quot;Jos &quot; &amp;lt;DELjos@jasenDEL.nl&amp;gt; wrote in message &lt;br&gt;
&amp;lt;g4kqmi$ook$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
[..]&lt;br&gt;
&amp;gt; 2) determine at which lines data starts, e.g. line X&lt;br&gt;
&amp;gt;    This is the real problem!&lt;br&gt;
&amp;gt;    p = regexp(s,'[A-Za-z]') will give a cell array with &lt;br&gt;
non-&lt;br&gt;
&amp;gt; empty cells when a line contains text (but how to deal &lt;br&gt;
with &lt;br&gt;
&amp;gt; scientific notation ...). See help regexp for more &lt;br&gt;
options.&lt;br&gt;
&amp;gt;    X = max(find(~cellfun('isempty',p))) + 1&lt;br&gt;
&amp;gt; &lt;br&gt;
[..]&lt;br&gt;
&lt;br&gt;
That's the crux! Depending on what you know in advance &lt;br&gt;
about the file, you have to care about scientific notation, &lt;br&gt;
as you mentioned, final header lines containing delimiters, &lt;br&gt;
signs, whitespaces or other special characters only or just &lt;br&gt;
being empty, and possibly NaN and Inf occurrences in the &lt;br&gt;
number section.&lt;br&gt;
All in all, this can result in quite a lengthy piece of &lt;br&gt;
code.&lt;br&gt;
&lt;br&gt;
Andres</description>
    </item>
  </channel>
</rss>

