필터 지우기
필터 지우기

Loading binary data into custom array

조회 수: 3 (최근 30일)
MPan
MPan 2020년 12월 23일
댓글: MPan 2021년 1월 5일
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
MPan
MPan 2020년 12월 23일
Thanks Walter, I'm going to give this a shot. This seems promising.
MPan
MPan 2021년 1월 5일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

weikang zhao
weikang zhao 2020년 12월 23일
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
MPan
MPan 2020년 12월 23일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile 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!

Translated by