How to import large textfile
5 views (last 30 days)
Show older comments
Hi EVERYONE I'm new to matlab, I've been trying to import large text file .asc to matlab. is there anyone can help. the file contains 59615 (24*24)matrix. I've attached small part of the file. When I import the whole file I get an error while if I import small part it works fine!! I don't think it's memory problem, can anyone help please???
4 Comments
Accepted Answer
Cedric
on 9 Jun 2014
Edited: Cedric
on 9 Jun 2014
Here is one way to proceed
fId = fopen( 'omar_1.txt', 'r' ) ;
buf = fscanf( fId, '%f', Inf ) ;
fclose( fId ) ;
bSize = 24*24 + 1 ;
nBlocks = length( buf ) / bSize ;
data = cell( nBlocks, 1 ) ;
for bId = 1 : nBlocks
bBnds = ((bId-1)*bSize+2) : (bId*bSize) ;
data{bId} = reshape( buf(bBnds), 24, 24 ).' ;
end
At the end, you have your matrices in the cell array data:
>> data
data =
[24x24 double]
[24x24 double]
[24x24 double]
[24x24 double]
[24x24 double]
[24x24 double]
[24x24 double]
[24x24 double]
[24x24 double]
so data{1} is the first matrix. There are other approaches, but they a probably less efficient if your file is really large.
4 Comments
More Answers (0)
See Also
Categories
Find more on Text Data Preparation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!