我制作了这个程序,用户可以输入 2009 年至 2011 年之间的一年,并获取显示在图表上的所选年份的雪深和气温数据。
我有一个 xls 文件,用于记录从第 1 天到第 365 天的每一天的温度。我还有另一个 xls 文件,用于记录从第 1 天到第 212 天的雪深。因此,有些日子他们懒得测量雪深,因为当时是夏天无论如何。 4 月 30 日至 10 月 1 日期间,他们没有测量积雪深度。我想在 4 月 30 日到 10 月 1 日之间添加 153 个零,这样加起来就是 365 天。
第 121 天 = 4 月 30 日
下载空气温度 xls:https://dl.dropbox.com/u/11241083/airtemp2009_2011.xls https://dl.dropbox.com/u/11241083/airtemp2009_2011.xls
下载雪深 xls:https://dl.dropbox.com/u/11241083/snow2009_2011.xls https://dl.dropbox.com/u/11241083/snow2009_2011.xls
这是到目前为止的代码:
chosenyear = input('Type in year: ');
snowdepth = xlsread('snow2009_2011.xls');
snowdepth2009 = snowdepth(:,1);
snowdepth2010 = snowdepth(:,2);
snowdepth2011 = snowdepth(:,3);
airtemp = xlsread('airtemp2009_2011.xls');
airtemp2009 = airtemp(:,1);
airtemp2010 = airtemp(:,2);
airtemp2011 = airtemp(:,3);
if chosenyear == 2009
figure(1);
plot(snowdepth2009, 'b');
title(['Snowdepth/airtemp ' num2str(chosenyear)]);
xlabel('Days/months');
ylabel('data');
grid on
datetick('x','m');
hold on
plot(airtemp2009, 'r');
legend('snow depth in cm','air temp in Celsius');
elseif chosenyear == 2010
figure(2);
plot(snowdepth2010, 'b');
title(['Snowdepth/airtemp ' num2str(chosenyear)]);
xlabel('Days/months');
ylabel('data');
grid on
datetick('x','m');
hold on
plot(airtemp2010, 'r');
legend('snow depth in cm','air temp in Celsius');
elseif chosenyear == 2011
figure(3);
plot(snowdepth2011, 'b');
title(['Snowdepth/airtemp ' num2str(chosenyear)]);
xlabel('Days/months');
ylabel('data');
grid on
datetick('x','m');
hold on
plot(airtemp2011, 'r');
legend('snow depth in cm','air temp in Celsius');
else
disp('NB! Type in 2009, 2010 or 2011');
filename.m
end