- Endianess: If the MATLAB code explicitly specifies little-endian format but the C code is running on a big-endian system, the bytes will be written in a different order.
- Data Type: Make sure that 'Word32' in C is indeed a 32-bit integer ('int32_t' or equivalent). If it's not, the size of the data being written will be different.
- File Mode: If the file is not opened in binary mode in C ("wb"), it could cause differences in how the data is written, especially on systems like Windows where text mode and binary mode treat certain characters differently (e.g., newline translation).
- Initial File State: If the file pointed to by 'output_file' is not in the same initial state before each write operation (e.g., if it contains different data or is at different positions within the file), the resulting output will differ.
- Data in Memory: Ensure that 'inp_ptr' is pointing to the same data with the same values in both the C and MATLAB environments before the write operations.
I'm doing pdm to pcm conversion and want output file to be generated in .pcm format currently using .bin file.
18 次查看(过去 30 天)
显示 更早的评论
currently im using fwrite to write data in output file with int32 and little endian format in .bin file as .pcm is not available
" fwrite( output_file ,inp_ptr ,'int32' , 'l' ); " for matlab
output:
-----> C and matlab output files are not matching
while my C file command is " fwrite(inp_ptr, sizeof(Word32), 8, output_file); " output file saved as .pcm .
output:
how to get same output as C ?
0 个评论
回答(1 个)
Paras Gupta
2023-12-17
Hi Uma,
I understand that the output in MATLAB and C do not match when you try to write data in an output file.
The reason you might be seeing different outputs between the two could be due to several factors:
Moreover, the file extension itself (.bin or .pcm) does not affect the actual content of the file. The difference is purely in the naming convention, which might be used by software to infer the intended use of the file.
Hope this helps.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 PCM 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!