Loading binary data into custom array

11 Ansichten (letzte 30 Tage)
MPan
MPan am 23 Dez. 2020
Kommentiert: MPan am 5 Jan. 2021
Hi,
I'm trying to load in a binary data file with a unique data structure {uint32, uint32, double, double, double,.., double, uint32}. After doing a little bit of research, folks on the forums have recommended using the function "memmapfile()" to read in binary data files with custom arrays. The problem with this is my data is all in big-endian format and memmapfile() outputs the data in little endian format.
I'm looking for help as to whether or not memmapfile() can be produce a big-endian output without me using functions like swapbytes() or typecast() as it increases the loading/processing of the data significantly.
Any help is deeply appreciated,
MP
  3 Kommentare
MPan
MPan am 23 Dez. 2020
Thanks Walter, I'm going to give this a shot. This seems promising.
MPan
MPan am 5 Jan. 2021
Walter,
I had the chance to review this code today and it appears that the MappedTensor does not provide the ability to read data into custom data structures based on the issue that was opened in Github. The author suggested loading the data into different binary files to then be stored in the various fields of the struct but that doesn't really seem to be any more efficient than using fread().
Regards,
Mithul

Melden Sie sich an, um zu kommentieren.

Antworten (1)

weikang zhao
weikang zhao am 23 Dez. 2020
The “fopen” function may be more flexible. It allows you to access the data in the binary file in any way, of course, including any data type and big-endian. The disadvantage is that it cannot be implemented with a simple function, and a script needs to be written.
  1 Kommentar
MPan
MPan am 23 Dez. 2020
Hi Weikang,
That was also a function I used during my first attempt; however, reading in binary files and assigning them to my custom struct one field via a "for-loop" was very time consuming. I also have several different structs that have variations in what order the fields and data types are in so I'm looking to create a generic script that can handle this for me.
Thanks for the suggestion.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Low-Level File I/O finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by