matlab 文件读写函数学习笔记 fopen fwrite fread fgetl fgets ftell fseek

专供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);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值