MATLAB读取txt中数据

来源:互联网 发布:怎么在淘宝上找115会员 编辑:程序博客网 时间:2024/06/10 14:43
fileID = fopen(filename)

fileID = fopen(filename, permission)

fileID = fopen(filename, permission, machineformat)

fileID = fopen(filename, permission, machineformat, encoding)

[fileID, message] = fopen(filename, ...)

fIDs = fopen('all')

[filename, permission, machineformat, encoding] = fopen(fileID)


实例 1:

fid = fopen('data.txt','r');    %Open the txt
a=[];
while ~feof(fid)                %judge fie end
    tline=str2num(fgetl(fid));  %read a line&turn char to double
    a=[a;tline];                %write the line to a
end

实例2:

fid=fopen('fx.txt','r');
%得到文件号
[f,count]=fscanf(fid,'%f %f',[12,90]);
%把文件号1的数据读到f中。其中f是[12 90]的矩阵
%这里'%f %f'表示读取数据的形势,他是按原始数据型读出
fclose(fid);
%关闭文件
另外有的txt文件还可以用load来打开
其语句为

f=load('fx.txt)



0 0