<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/261875</link>
    <title>MATLAB Central Newsreader - alternative to laod file?</title>
    <description>Feed for thread: alternative to laod file?</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>Tue, 29 Sep 2009 10:36:04 -0400</pubDate>
      <title>alternative to laod file?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/261875#683355</link>
      <author>M K</author>
      <description>Hi !&lt;br&gt;
&lt;br&gt;
I have a series of large ASCII files which I want to process using Matlab. I do that by loading each file using the 'load(filename)' function. Howeever, I 've noticed that some of the files are incomplete and therefore the number of columns in the last line are not consistent with the rest of the rows in a given file. So what I'd like to do is load the incomplete files to only a certain number of rows (ie to the row number that is complete). &lt;br&gt;
&lt;br&gt;
So for ex if the original file size is : 1000 rows x 1000 columns (the real numbers are much much larger), I want to load the file to 999 rows x 1000 columns since the 1000th row is corrupt. Is there any way I could do this in Matlab. One option would be to open each corrupt ASCII file and delete the last row manually but I have &amp;gt;500 files! So wondered if there was a way of doing this on my script file? &lt;br&gt;
&lt;br&gt;
Any help will be much appreciated. </description>
    </item>
    <item>
      <pubDate>Tue, 29 Sep 2009 10:46:16 -0400</pubDate>
      <title>Re: alternative to laod file?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/261875#683359</link>
      <author>Rune Allnor</author>
      <description>On 29 Sep, 12:36, &quot;M K&quot; &amp;lt;mah...@mathworks.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; Hi !&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I have a series of large ASCII files which I want to process using Matlab. I do that by loading each file using the 'load(filename)' function. Howeever, I 've noticed that some of the files are incomplete and therefore the number of columns in the last line are not consistent with the rest of the rows in a given file. So what I'd like to do is load the incomplete files to only a certain number of rows (ie to the row number that is complete).&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; So for ex if the original file size is : 1000 rows x 1000 columns (the real numbers are much much larger), I want to load the file to 999 rows x 1000 columns since the 1000th row is corrupt. Is there any way I could do this in Matlab. One option would be to open each corrupt ASCII file and delete the last row manually but I have &amp;gt;500 files! So wondered if there was a way of doing this on my script file?&lt;br&gt;
&lt;br&gt;
If you know the number of lines in advance, TEXTSCAN can be&lt;br&gt;
used to read a specified number of lines.&lt;br&gt;
&lt;br&gt;
If you don't know the number of lines in advance, I would have&lt;br&gt;
read each line, one by one, and parsed them to see if they are&lt;br&gt;
complete.&lt;br&gt;
&lt;br&gt;
Rune</description>
    </item>
    <item>
      <pubDate>Tue, 29 Sep 2009 10:57:02 -0400</pubDate>
      <title>Re: alternative to laod file?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/261875#683361</link>
      <author>M K</author>
      <description>Thanks for your reply, Rune.&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&lt;br&gt;
I do know the number of  rows and columns of uncorrupt data (say for ex 999 x 1000).  So the following should work&lt;br&gt;
&lt;br&gt;
u=1:500;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;FID=ID=['Rx' num2str(u) '.txt']&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;D=texscan(FID,999,1000);&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
?</description>
    </item>
    <item>
      <pubDate>Tue, 29 Sep 2009 12:38:47 -0400</pubDate>
      <title>Re: alternative to laod file?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/261875#683379</link>
      <author>Leslie McBrayer</author>
      <description>&amp;gt; I do know the number of  rows and columns of uncorrupt data (say for ex &lt;br&gt;
&amp;gt; 999 x 1000).  So the following should work&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; u=1:500;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;   FID=ID=['Rx' num2str(u) '.txt']&lt;br&gt;
&amp;gt;   D=texscan(FID,999,1000);&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; ?&lt;br&gt;
&lt;br&gt;
Not quite.  With textscan, you need to:&lt;br&gt;
* Open the file with fopen to get fid.&lt;br&gt;
* Describe the columns with format specifiers such as %d or %f.&lt;br&gt;
* Specify only a single repetition factor (not rows and columns).&lt;br&gt;
&lt;br&gt;
For your case, I would recommend the dlmread function.  For example:&lt;br&gt;
&lt;br&gt;
for u=1:500;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;filename = sprintf('Rx%d.txt', u);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;D = dlmread(filename, '', [0 0 999 1000]);&lt;br&gt;
&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
For more info, type &quot;doc dlmread&quot; at the command prompt. </description>
    </item>
    <item>
      <pubDate>Tue, 29 Sep 2009 14:49:01 -0400</pubDate>
      <title>Re: alternative to laod file?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/261875#683422</link>
      <author>M K</author>
      <description>Thanks for the replies. The dlmread function isn't happy with my input files. I think the issue is that each of files are approx 1.2GB!!! &lt;br&gt;
&lt;br&gt;
I tried the fscanf function- strangely it doesn't extract the numbers from the ASCII file. My code is below&lt;br&gt;
&lt;br&gt;
for u=1:500&lt;br&gt;
&amp;nbsp;&amp;nbsp;filename=['Rx' num2str(u) '.txt'];&lt;br&gt;
&amp;nbsp;&amp;nbsp;fid = fopen(filename);&lt;br&gt;
&amp;nbsp;&amp;nbsp;a = fscanf(fid, '%g %g', [14484 5557]);    % It has 14484 rows x 5557 columns.&lt;br&gt;
&amp;nbsp;&amp;nbsp;fclose(fid)&lt;br&gt;
&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
The above is what I would use instead of D=load(filename) which works for uncorrupt data but sadly not in the corrupt files due to lack of symmetry. &lt;br&gt;
&lt;br&gt;
It seems strange that I can't use the std functions. Would appreciate any thoughts/help on this. Thanks in advance.</description>
    </item>
    <item>
      <pubDate>Tue, 29 Sep 2009 16:07:02 -0400</pubDate>
      <title>Re: alternative to laod file?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/261875#683456</link>
      <author>M K</author>
      <description>could someone please help. &lt;br&gt;
&lt;br&gt;
&lt;br&gt;
I've tried many things but I can't seem to get any function to do what load does for me. </description>
    </item>
    <item>
      <pubDate>Tue, 29 Sep 2009 16:35:19 -0400</pubDate>
      <title>Re: alternative to laod file?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/261875#683466</link>
      <author>Andres </author>
      <description>&quot;M K&quot; &amp;lt;maha_k@mathworks.com&amp;gt; wrote in message &amp;lt;h9tbb6$rma$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; could someone please help. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I've tried many things but I can't seem to get any function to do what load does for me. &lt;br&gt;
&lt;br&gt;
&lt;br&gt;
A small script that uses txt2mat from the file exchange. txt2mat is not necessarily sensitive to incomplete rows, but it must loop through the file due to your huge memory demand (should be quite quick, though).&lt;br&gt;
Try+vary if you like (i can't test here)&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
% your parameters&lt;br&gt;
fn = 'c:\myhugefile.txt';&lt;br&gt;
numRow  = 14484;&lt;br&gt;
numCol  = 5557;&lt;br&gt;
rowStep = 1000;&lt;br&gt;
&lt;br&gt;
% initializations&lt;br&gt;
D       = zeros(numRow,numCol);  % phew&lt;br&gt;
fp      = 0;&lt;br&gt;
rowStart= 1;&lt;br&gt;
&lt;br&gt;
% loop through file&lt;br&gt;
while rowStart &amp;lt;= numRow&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rowEnd = min(rowStart+rowStep-1,numRow);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[A,ffn,nh,SR,hl,fp] = txt2mat(fn,0,numCol,'%f',...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'RowRange',[1,rowEnd-rowStart+1],...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'FilePos',fp, 'ReadMode','block',...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'InfoLevel',0);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;D(rowStart:rowEnd,:) = A;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rowStart = rowEnd+1;&lt;br&gt;
end</description>
    </item>
  </channel>
</rss>

