MATLAB to CPP code
조회 수: 2 (최근 30일)
이전 댓글 표시
In MATLAB, it is quite convenient to implement reading binary files with data types that are not several-integer-number of bytes, like
data = fread(fid, fsize, 'bit12');
I feel extremely frustrated about how to correctly convert this expression to C++ code?
댓글 수: 0
답변 (1개)
arushi
2024년 5월 28일
Hi Mikhun,
When dealing with non-standard data types like a 12-bit number which isn’t natively supported in C++. In MATLAB, fread with 'bit12' allows you to read data as 12-bit units directly, but in C++, you may need to read the data into a larger standard type and then extract the 12-bit values manually.Read the data into an array of a standard data type that is larger than 12 bits, such as uint16_t (16 bits) and then extract the 12-bit values from the array of 16-bit numbers.
Hope this helps.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!