标签:fopen fclose fread fwrite fseek
和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 >>
本文出自 “xinyi_xft” 博客,谢绝转载!
标签:fopen fclose fread fwrite fseek
原文地址:http://siyixingfeng.blog.51cto.com/6786071/1714451