专供bin文件读写的函数
fwrite(fileID,A) writes the elements of array A as 8-bit unsigned integers to a binary file in column order
fread(fileID) reads data from an open binary file
freq_data_file = sprintf('./symbol%d.bin',0);
pf = fopen(freq_data_file,'rb');
fopen(pf)
if -1 == pf
disp('error open file')
else
freq_data1 = fread(pf, inf, 'int32');
fclose(pf);
freq_data = complex(freq_data1);%此处应该分16bit后再转
freq_data(1:5)
end
fopen(fileID) returns the file name that a previous call to fopen used when it opened the file specified by fileID.
status = feof(fileID) returns the status of the end-of-file indicator ;1 if a previous operation set the end-of-file indicator for the specified file. Otherwise, feof returns a 0.
tline = fgetl(fileID) returns the next line of the specified file, removing the newline characters.
fprintf(formatSpec,A1,...,An) formats data and displays the results on the screen
fprintf(fileID,formatSpec,A1,...,An) writes the data to a text file
fprintf用于格式化输出到文件中与输出到命令行窗口并无本质区别
frewind(fileID) sets the file position indicator to the beginning of a file.
position = ftell(fileID) returns the current location of the position pointer in the specified file
fgets Read line from file, keeping newline characters 带回车符
fgetl Read line from file, removing newline characters 不带回车符
fid = fopen('badpoem.txt');
tline1 = fgetl(fid) % read first line
status = feof(fid);
if 1 == status
fprintf('printf on screen file end\n');
end
position = ftell(fid)
frewind(fid)
sline1 = fgets(fid)
fclose(fid);
matlab 文件读写函数学习笔记 fopen fwrite fread fgetl fgets ftell fseek
最新推荐文章于 2024-09-18 23:17:26 发布