I have a quite big binary file that contains the information in a volume of about one GB of data.
我有一个非常大的二进制文件,其中包含大约1 GB数据量的信息。
I am trying to split one GB of .bin
file into 4 files of 256 MB each, I am getting no help.
我试图将一个GB的.bin文件分成4个256 MB的文件,我没有得到帮助。
I tried using textscan
and memmapfile
functions but of no use.
我尝试使用textscan和memmapfile函数但没有用。
Any help on this?
对此有何帮助?
1 个解决方案
#1
MATLAB can both read and write binary files.
MATLAB可以读写二进制文件。
Try using the fopen()
, fread()
/fwrite()
, and fclose()
commands.
尝试使用fopen(),fread()/ fwrite()和fclose()命令。
To read a binary file into MATLAB, first open the file for reading.
要将二进制文件读入MATLAB,首先打开文件进行读取。
Then the magic comes -- you need to know the context/structure of the binary data inside the .bin
file so as to be able to scan the data thereafter into variables using the correct format.
然后魔术来了 - 您需要知道.bin文件中二进制数据的上下文/结构,以便能够使用正确的格式将数据扫描到变量中。
fHANDLE = fopen( 'aHugeBinFileNAME.bin','r'); % Open the binary file for reading with a fileHandle fHANDLE
[dVECTOR,count] = fread( fHANDLE, 'int16' ); % Scan the data into a vector of int16 values, in this case called dVECTOR
fclose( fHANDLE); % Close the file
Anyway, get more details about fileIO services via help fread()
et al on more options to read "first/next" 256MB of the huge input-file for your specific context of use.
无论如何,通过help fread()等获取有关fileIO服务的更多详细信息,以获取更多选项,以便为您的特定使用环境读取“第一个/下一个”256MB的巨大输入文件。
dVECTOR_256M = fread( fHANDLE, 256*1024*1024, 'uint8', 0, 'b' ); % Big-Endian convention
#1
MATLAB can both read and write binary files.
MATLAB可以读写二进制文件。
Try using the fopen()
, fread()
/fwrite()
, and fclose()
commands.
尝试使用fopen(),fread()/ fwrite()和fclose()命令。
To read a binary file into MATLAB, first open the file for reading.
要将二进制文件读入MATLAB,首先打开文件进行读取。
Then the magic comes -- you need to know the context/structure of the binary data inside the .bin
file so as to be able to scan the data thereafter into variables using the correct format.
然后魔术来了 - 您需要知道.bin文件中二进制数据的上下文/结构,以便能够使用正确的格式将数据扫描到变量中。
fHANDLE = fopen( 'aHugeBinFileNAME.bin','r'); % Open the binary file for reading with a fileHandle fHANDLE
[dVECTOR,count] = fread( fHANDLE, 'int16' ); % Scan the data into a vector of int16 values, in this case called dVECTOR
fclose( fHANDLE); % Close the file
Anyway, get more details about fileIO services via help fread()
et al on more options to read "first/next" 256MB of the huge input-file for your specific context of use.
无论如何,通过help fread()等获取有关fileIO服务的更多详细信息,以获取更多选项,以便为您的特定使用环境读取“第一个/下一个”256MB的巨大输入文件。
dVECTOR_256M = fread( fHANDLE, 256*1024*1024, 'uint8', 0, 'b' ); % Big-Endian convention