fseek and parallel reading (vector position)

4 ビュー (過去 30 日間)
MatG
MatG 2015 年 9 月 15 日
回答済み: Guillaume 2015 年 9 月 15 日
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.

回答 (1 件)

Guillaume
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);

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by