How to import large textfile
6 次查看(过去 30 天)
显示 更早的评论
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???
采纳的回答
Cedric
2014-6-9
编辑:Cedric
2014-6-9
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Data Preparation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!