<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/241180</link>
    <title>MATLAB Central Newsreader - Problems with importing large text files</title>
    <description>Feed for thread: Problems with importing large text files</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>Wed, 17 Dec 2008 10:15:33 -0500</pubDate>
      <title>Problems with importing large text files</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/241180#617529</link>
      <author>Sven B?</author>
      <description>Hi,&lt;br&gt;
from my PSPICE-simulation I get a text-file with the simulated data.&lt;br&gt;
The text file is approx. 500MB.&lt;br&gt;
The data in the file consists of 101 columns and approx. 100000 rows.&lt;br&gt;
For Matlab it is not possible to import this file via the Import Wizard.&lt;br&gt;
The first row is normal text, the others should be numbers.&lt;br&gt;
The first row has no special delimiter. Sometimes there are 2 sometimes 4 blanks as delimiter.&lt;br&gt;
Each column is the result of a Monte Carlo analysis.&lt;br&gt;
&lt;br&gt;
The Import wizard starts up an then hangs on the point &quot;creating preview&quot;.&lt;br&gt;
&lt;br&gt;
Does anyone can help me?&lt;br&gt;
&lt;br&gt;
Regards,&lt;br&gt;
&lt;br&gt;
Sven</description>
    </item>
    <item>
      <pubDate>Wed, 17 Dec 2008 10:50:19 -0500</pubDate>
      <title>Re: Problems with importing large text files</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/241180#617537</link>
      <author>Sebastiaan </author>
      <description>You can write your own import function using fopen:&lt;br&gt;
&lt;br&gt;
Assuming your data looks something like this:&lt;br&gt;
Comments&lt;br&gt;
2.35 93.1 294.1 593.1&lt;br&gt;
23.1 345.4 127812947.12834 1282881.1&lt;br&gt;
&lt;br&gt;
Then:&lt;br&gt;
A = zeros(100000, 101);  % This is ~ 800MB, are you sure you have enough memory?&lt;br&gt;
&lt;br&gt;
fid = fopen('data.txt', 'r');&lt;br&gt;
row = 1;&lt;br&gt;
&lt;br&gt;
% Skip first line&lt;br&gt;
tline = fgetl(fid);&lt;br&gt;
&lt;br&gt;
while 1&lt;br&gt;
&amp;nbsp;&amp;nbsp;tline = fgetl(fid);&lt;br&gt;
&amp;nbsp;&amp;nbsp;if ~ischar(tline), break, end&lt;br&gt;
&amp;nbsp;&amp;nbsp;A(row, :) = str2double(regexp(tline, ' ', 'split'));&lt;br&gt;
end&lt;br&gt;
fclose(fid);&lt;br&gt;
&lt;br&gt;
If you have binary data, use fread instead.&lt;br&gt;
&lt;br&gt;
Good luck.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&quot;Sven B?&quot; &amp;lt;sven.boehm@contiautomotive.com&amp;gt; wrote in message &amp;lt;giajg4$f3t$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; from my PSPICE-simulation I get a text-file with the simulated data.&lt;br&gt;
&amp;gt; The text file is approx. 500MB.&lt;br&gt;
&amp;gt; The data in the file consists of 101 columns and approx. 100000 rows.&lt;br&gt;
&amp;gt; For Matlab it is not possible to import this file via the Import Wizard.&lt;br&gt;
&amp;gt; The first row is normal text, the others should be numbers.&lt;br&gt;
&amp;gt; The first row has no special delimiter. Sometimes there are 2 sometimes 4 blanks as delimiter.&lt;br&gt;
&amp;gt; Each column is the result of a Monte Carlo analysis.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The Import wizard starts up an then hangs on the point &quot;creating preview&quot;.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Does anyone can help me?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Regards,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Sven</description>
    </item>
    <item>
      <pubDate>Wed, 17 Dec 2008 11:06:02 -0500</pubDate>
      <title>Re: Problems with importing large text files</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/241180#617538</link>
      <author>Andres </author>
      <description>&quot;Sven B?&quot; &amp;lt;sven.boehm@contiautomotive.com&amp;gt; wrote in message &amp;lt;giajg4$f3t$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; from my PSPICE-simulation I get a text-file with the simulated data.&lt;br&gt;
&amp;gt; The text file is approx. 500MB.&lt;br&gt;
&amp;gt; The data in the file consists of 101 columns and approx. 100000 rows.&lt;br&gt;
&amp;gt; For Matlab it is not possible to import this file via the Import Wizard.&lt;br&gt;
&amp;gt; The first row is normal text, the others should be numbers.&lt;br&gt;
&amp;gt; The first row has no special delimiter. Sometimes there are 2 sometimes 4 blanks as delimiter.&lt;br&gt;
&amp;gt; Each column is the result of a Monte Carlo analysis.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The Import wizard starts up an then hangs on the point &quot;creating preview&quot;.&lt;br&gt;
&lt;br&gt;
Seems like the import wizard is overchallenged... but i guess you can go without it. You obviously know everthing about the the file layout, so a textscan (+ fgetl) should do, like&lt;br&gt;
&lt;br&gt;
nCol = 101;&lt;br&gt;
fid = fopen('myfile.txt');&lt;br&gt;
firstRowString = fgetl(fid);&lt;br&gt;
data = textscan(fid, repmat('%f',1,nCol),'CollectOutput', true);&lt;br&gt;
fclose(fid)&lt;br&gt;
&lt;br&gt;
Maybe you have to adjust for the delimiters in the data section or other details, see the textscan doc. I *assume* you'll get no memory issues in this way.</description>
    </item>
    <item>
      <pubDate>Wed, 17 Dec 2008 11:59:04 -0500</pubDate>
      <title>Re: Problems with importing large text files</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/241180#617547</link>
      <author>Sven B?</author>
      <description>Thanks to both of you.&lt;br&gt;
The one from Andres was the thing that saved my day....&lt;br&gt;
&lt;br&gt;
Sven</description>
    </item>
  </channel>
</rss>

