1、使用fgetl和fgets函数读取文本文件数据
从文本文件中读取一行数据
data=fgetl(fileID)
data=fgets(fileID)
temp.txt
Day1
temp1=13
temp2=25
temp3=16
Day2
temp1=14
temp2=25
temp3=16
Day3
temp1=14
temp2=26
temp3=17
运行:
>> fid=fopen('temp.txt');
>> str1=fgetl(fid);
>> fseek(fid,0,'bof');
>> str2=fgets(fid);
>> fclose(fid);
>> uint8(str1)
ans =
68 97 121 49
>> uint8(str2)
ans =
68 97 121 49 13 10
2、使用fileread函数读取文本文件数据
text=fileread(filename)
>> s=fileread('temp.txt')
s =
Day1
temp1=13
temp2=25
temp3=16
Day2
temp1=14
temp2=25
temp3=16
Day3
temp1=14
temp2=26
temp3=17