主题:请教 如何在文件中读取数据
caispring
[专家分:0] 发布于 2007-10-18 15:26:00
文件数据有两种格式,字符和浮点数据,想读取文件中的数据,不知道该怎么读.
回复列表 (共2个回复)
沙发
tinahu [专家分:30] 发布于 2007-10-18 16:10:00
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
板凳
caispring [专家分:0] 发布于 2007-10-23 14:57:00
谢谢,我试一试
我来回复