fseek and parallel reading (vector position)
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Guillaume
el 15 de Sept. de 2015
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 comentarios
Ver también
Categorías
Más información sobre Low-Level File I/O en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!