作业帮 > 综合 > 作业

matlab文件读取与读出 谁能帮我看看我哪出错了,

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/29 11:20:37
matlab文件读取与读出 谁能帮我看看我哪出错了,
1.在12h内,每隔1h测量一次温度,温度依次为:5,8,9,15,25,29,31,30,22,25,27,24.将每隔1/10h估计一次温度值的时间和温度写入temps.dat中,然后通过二进制文件操作读取temps.dat中的数据,并画出温度随时间变化的曲线.
%二进制文件的创建
fp=fopen('D:\decimal.dat','wb');
temp=[5 8 9 15 25 29 31 30 22 25 27 24]
time=12
fwrite(fp,temp,'int 16')
fwrite(fp,time,'int 16')
number=240
r=randperm(number);
a=2
b=number/a
z=reshape(r,a,b)
fwrite(fp,a,'int 16')
fwrite(fp,b,'int 16')
[m,n]=size(z)
for i=1:m
for j=1:n
fwrite(fp,z(i,j),'bit 16')
end
end
fclose(fp)
%在12h内,每隔1h测量一次温度,温度依次为:5,8,9,15,25,29,31,30,22,25,27,24.
%将每隔1/10h估计一次温度值的时间和温度写入temps.dat中,然后通过二进制文件操作读取temps.dat中的数据,
%并画出温度随时间变化的曲线.
%二进制文件的创建
fp=fopen('D:\My Documents\MATLAB\decimal.dat','wb');
temp=[5 8 9 15 25 29 31 30 22 25 27 24];
time=1:12;
fwrite(fp,temp);
fwrite(fp,time);
subplot(2,1,1)
plot(time,temp,'b-x')
fclose(fp);
times=0:0.1:12;
temps=interp1(time,temp,times);
f=fopen('D:\My Documents\MATLAB\temps.dat','wb');
fwrite(f,temps);
fwrite(f,times);
subplot(2,1,2)
plot(times,temps,'r-.*')
fclose(f);
按上面语句保存后运行,试试