Loading a large text file into MATLAB

geodavegeodave Arizona
edited November 2010 in Science & Tech
Hello everyone,

I have a question about loading a large (~100 Mb) 3-column, space-delimited text file into the MATLAB workspace. Here's what I've tried so far:

(1) Using the "load" command. There's a noticeable delay time here (~1 min) considering I'm running a 6 Gb RAM, 2.4 GHz laptop (which is probably a slug compared to what you guys have, but it's all I can afford at the moment! ;) ).

(2) Using the "textscan" command as follows:
>> fid = fopen('very_large_text_file.txt');
>> data = textscan(fid, '%f %f %f', 'delimiter', ' ');
Option (2) above appears to be efficient (takes a couple of seconds to complete on my laptop). However, when I try to plot one column against another using "plot" as follows:
figure(1); plot(data(:,1), data(:,2), 'k.');
I get the following error:
??? Error using ==> plot
Conversion to double from cell is not possible.
Now, I'm not very familiar with cell arrays, so I'm blaming this error on my lack of MATLABing skills. And so I turn to you guys. Any ideas or suggestions as to how I can plot one column against the other after loading the text file using "textscan", or perhaps converting the cell array to a regular array (if at all possible)?

Any suggestions or ideas would be much appreciated!

geodave

Comments

  • drasnordrasnor Starship Operator Hawthorne, CA Icrontian
    edited November 2010
    Cell arrays don't necessarily contain a homogeneous set of data so many of the standard tools don't work with them very well. Read the MathWorks helpfile and note the example on accessing elements of data within cell arrays (i.e. the vector index of a vector stored in a single element of the cell array.)
  • geodavegeodave Arizona
    edited November 2010
    Great. Thank you, drasnor. I think I've figured it out. Here's the code for anyone interested in how I did it:

    (1) Used the textscan command I mentioned above to read the large text file.
    (2) Assigned the columns as follows:
    x_column = data{1};
    y_column = data{2};
    
    (3) Plotted x vs. y as follows:
    plot(x_column, y_column, 'k.')
    
    Cheers,

    geodave
Sign In or Register to comment.