fseek and parallel reading (vector position)
4 ビュー (過去 30 日間)
古いコメントを表示
fid = fopen('file','rb');
fseek(fid,startposition,'bof');
fread(fid,quantyToRead,'single');
This code will take me to the position in the binary file, for instance a txt file, (specified by fid), and I can read "quantyToRead" elements.
Is there a way, that "startposition" be a vector of positions (as opposed to a scalar), for instance startposition = [1000 40000 80000], and for each position I read "quantyToRead" numvbers. I would like to avoid a for loop to sequentially process and instead do reading all at once. The reason is I have about 10,000 positions to read and and a for loop will take a long time.
0 件のコメント
回答 (1 件)
Guillaume
2015 年 9 月 15 日
file i/o is essentially a sequential operation unless you have a specially designed file system / hardware architecture. Base matlab certainly does not have any concept of parallel i/o and I'm not sure the parallel processing toolbox has either.
My advice would be to read the whole file and then slice the data as appropriate:
fid = fopen('file', 'rb');
alldata = fread(fid, Inf, 'single')
startpositions = [1000, 40000, 80000];
sliceddata = arrayfun(@(sp) alldata(sp:sp+quantyToRead), startpositions, 'UniformOutput', false);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Low-Level File I/O についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!