回 帖 发 新 帖 刷新版面

主题:请教 如何在文件中读取数据

文件数据有两种格式,字符和浮点数据,想读取文件中的数据,不知道该怎么读.

回复列表 (共2个回复)

沙发

fid=fopen('c:\file.dat'); % open the file
i=1;
while 1
    tline = fgetl(fid); % get a line of the file 
    str_read(i)=tline(p1:p2); % string 
    num_read(i)=str2num(tline(p3:p4)); % get data line
    %p* start and stop position of string or number
    i=i+1; % i is indicate the line number
end
fclose(fid); % close file

板凳

谢谢,我试一试

我来回复

您尚未登录,请登录后再回复。点此登录或注册