I reproduced your result on R2013a, Win7
>> [CR,FS] = cssm(1e5); whos('CR','FS')
Name Size Bytes Class Attributes
CR 100000x1 800000 double
FS 100000x1 800000 double
>> [CR,FS] = cssm(1e3); whos('CR','FS')
Name Size Bytes Class Attributes
CR 1x1001 8008 double
FS 1000x1 8000 double
where
function [ CR, FS ] = cssm( N )
str = repmat( '1.1,', 1, N );
fid = fopen( 'cssm.txt', 'w' );
fprintf( fid, '%s', str );
fclose( fid );
CR = csvread( 'cssm.txt' );
fid = fopen( 'cssm.txt', 'r' );
FS = fscanf( fid, '%f,' );
fclose( fid );
end
csvread is based on textscan and contains a bit of automagic. I guess, it was never intended for rows that long, i.e. files without new lines.
 
without the ending comma
And without the ending comma, cvsread returns a row for the large file.
>> [CR,FS] = cssm(1e5); whos('CR','FS')
Name Size Bytes Class Attributes
CR 1x100000 800000 double
FS 100000x1 800000 double
 
textscan with empty formatSpec
csvread calls textscan with formatSpec set to an empty string. That option of textscan is not documented. It makes a difference in this special case.
>> [CR,FS,TS1,TS2] = cssm(1e3); whos('CR','FS','TS1','TS2')
Name Size Bytes Class Attributes
CR 1x1001 8008 double
FS 1000x1 8000 double
TS1 1000x1 8000 double
TS2 1x1001 8008 double
>> [CR,FS,TS1,TS2] = cssm(1e5); whos('CR','FS','TS1','TS2')
Name Size Bytes Class Attributes
CR 100000x1 800000 double
FS 100000x1 800000 double
TS1 100000x1 800000 double
TS2 100000x1 800000 double
where
function [ CR, FS, TS1, TS2 ] = cssm( N )
str = repmat( '1.1,', 1, N );
fid = fopen( 'cssm.txt', 'w' );
fprintf( fid, '%s', str(1:end) );
fclose( fid );
CR = csvread( 'cssm.txt' );
fid = fopen( 'cssm.txt', 'r' );
FS = fscanf( fid, '%f,' );
fclose( fid );
fid = fopen( 'cssm.txt', 'r' );
cac = textscan( fid, '%f', 'Delimiter',',' ...
, 'CollectOutput',true, 'EmptyValue',999 );
fclose( fid );
TS1 = cac{:};
fid = fopen( 'cssm.txt', 'r' );
cac = textscan( fid, '', 'Delimiter',',' ...
, 'CollectOutput',true, 'EmptyValue',999 );
fclose( fid );
TS2 = cac{:};
end
 
For the large file, all of the functions and options I tested fails to recognize the ending comma.
Best Answer