Azzera filtri
Azzera filtri

Indexing concurrent array elements and incrementing

5 visualizzazioni (ultimi 30 giorni)
I am dealing with large binary files and I am looking for an efficent way to index concurrent elements in an array after reading the raw binary data into an linear array.
For example:
Assume I have a linear array of 'uint8', which was read from a binary file. I know that a single "record" consists of 16 bytes and that the first three bytes of each record contains a time stamp.
What is the most efficient way to index the first three elements of the array, then increment by 13 and read the next three elements and so on until the end of the array?
For single byte elements in a recod I do the following, which is quite fast:
array = rawData(start:recordSz:end);
I would like to do something similar for multi byte elements.
Thanks!

Risposta accettata

J. Alex Lee
J. Alex Lee il 20 Ago 2020
First you could use "reshape" to create a 2D array whose rows corresponds to a record, then slice up the 2D array into however many variables constitute a record, of varying byte lengths
databytestream = % ... data stream
% how each record is organized: bytes per variable in record
varByteLengths = [13,3]
% compute the number of bytes per record
recordByteLength = sum(varByteLengths)
M = rand(23,16)
% reshape into number of records by number of bytes per record
M = reshape(databytestream,[],recordByteLength)
% compute start and end indices (within a record) for each variable
idx1 = cumsum(varByteLengths)
idx0 = [1,idx1(1:end-1) + 1]
% extract each variable as a new 2D array
for i = length(varByteLengths):-1:1
var{i} = M(:,(idx0(i):idx1(i)));
end

Più risposte (0)

Prodotti


Release

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by