-1

我制作了这个程序,用户可以输入 2009 年到 2011 年之间的一年,并在图表上显示所选年份的雪深和气温数据。

我有一个 xls 文件记录从第 1 天到第 365 天的每一天的温度。我还有另一个 xls 文件记录从第 1 天到第 212 天的雪深。所以有些日子他们懒得测量雪深,因为那是夏天无论如何。在 4 月 30 日至 10 月 1 日期间,他们没有测量雪深。我想添加 153 个零,代码介于 4 月 30 日和 1 月 1 日之间,所以它加起来是 365 天。

第 121 天 = 30. 四月

下载空气温度 xls:https ://dl.dropbox.com/u/11241083/airtemp2009_2011.xls

下载雪深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
4

1 回答 1

0

尝试这个,

snowDepth_full = zeros(365,3); % make a temporary variable to hold everything
snowDepth_full(1:121,:)  = snowDepth(1:121,:);   % First 121 days up to april 30
snowDepth_full(end-90,:) = snowDepth(122:end,:); % Last 91 days from oct 1 on
snowDepth = snowDepth_full;  % Copy it back 

然后和以前一样...

snowdepth2009 = snowdepth(:,1);
snowdepth2010 = snowdepth(:,2);
snowdepth2011 = snowdepth(:,3);
...
于 2012-11-23T20:51:21.030 回答