Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>By default <code>dlmread</code> tries to infer the delimiter from the file, by default it uses a white space as a delimiter.</p> <p>The only way I was able to replicate the problem you describe was by specifying <code>' '</code> as the delimiter. Are you sure you aren't doing this? </p> <p>Try making this change and see if it fixes your problem.</p> <pre><code>data = dlmread(inFile, '\t'); </code></pre> <p>If that doesn't fix your problem then I suspect that the problem is arising from the fact that the rows in your text file have a different number of columns. For example if you use <code>dlmread</code> to open a text file containing:</p> <pre><code>1 2 3 4 5 </code></pre> <p><code>dlmread</code> returns a matrix like this: </p> <pre><code>1 2 3 4 5 0 0 0 </code></pre> <p>This representation is wasteful as it is using 64 bytes (8 bytes per double * 8 double) to store 40 bytes of information. </p> <p>It could be that with these empty positions that a matrix representation of your file is simply too big, and so <code>dlmread</code> is returning your a vector instead to save memory.</p> <p>You can work around this though. If you only need a few rows at a time you can load a collection of rows from the file by specifying a <code>range</code> to <code>dlmread</code>. <em>Note</em> for this to work you have to know the maximum number of columns in the file, as <code>dlmread</code> won't let you read more than that number of columns.</p> <pre><code>r = [0 4]; %load the first 5 rows maxC = 10; % load up to 10 columns data = dlmread(inFile, '\t', [r(1), 0, r(2), maxX]); </code></pre> <p>You could then loop through the file loading the rows of interest, but you probably can't load them all into a matrix due to the memory constraints I mentioned earlier.</p> <p>If you need the entire dataset in memory then you should consider loading each row individually and saving them into a cell array. It takes a bit more work to get everything loaded but you could do that with something like this:</p> <pre><code>% open the file fid = fopen(fileName); % load each line as a single string tmp = textscan(fid, '%s', 'delimiter', '\n'); % textscan wraps its results in a cell, remove that wrapping rawText = tmp{1}; nLines = numel(rawText); %create a cell array to store the processed string data = cell(nLines, 1); for i = 1:nLines %scan a line of text returning a vector of doubles tmp = textscan(rawText{i}, '%f'); data{i} = tmp{1}; end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload