和C语言类似,Matlab也有类似的文件函数:
fid = fopen(filename, mode);%单引号标识 A = fread(fid, count, precision);%cout为precision指定精度的元素个数 count = fwrite(fid,A,precision);%将矩阵A中的元素写进fid标识的文件中,count为成功读取的元素的个数 fclose(fid);
此外,还有fseek函数,它的简单用法为:
status = fseek(fid,offset,origin)%offset为根据origin指定的坐标所作的位移
下面用一个程序演示具体的用法:
clc; ftxt = fopen(‘test.txt‘,‘r‘); A = fread(ftxt,10,‘uchar‘); fseek(ftxt,0,‘bof‘); B = fread(ftxt,10,‘uchar‘); fclose(ftxt); A = reshape(A,1,10); A = char(A); B = reshape(B,1,10); B = char(B); A B
结果为:
My name is B = My name is >>
时间: 2024-10-10 19:29:08