在数据集中查找一个月的最低温度

时间:2018-08-29 23:57:25

标签: matlab for-loop

我已经制作了一个函数,可以从给定月份和年份的特定时间内从数据集中提取所有特征。

看起来像exctractperiod(data, year, month, time)

我现在想找出多年来某个月份(例如1月)的最低温度。例如,如果我查看1997年至2006年之间的1月。现在,我想要1997年至2006年1月的最低注册温度。

到目前为止,我的进步(请记住,这只是我想要的粗略想法)

for i = 1:12
  for z = 1:x+1

    year=startyear:1:endyear;
    year(z)

   p = extractperiodtwo(DATA, year, month, time);    

end

我想知道如何编写for循环,以便说month 1经历1997-2006年,并找到最低的温度。然后,对于下一个循环,month 2经历了1997-2006年。然后应该重复到第12个月。

变量p存储YYYY月MM的所有温度。

不要把我的程序全部当回事,这只是一个粗糙的文章,让我自己对它的外观有所了解。也许可以澄清我的问题。

1 个答案:

答案 0 :(得分:0)

您可能正在寻找这样的东西:

mintemp = inf(1,12); % initialize to infinity for each month
for month = 1:12
  for year = 1997:2006
    p = extractperiodtwo(DATA, year, month, time);
    temp = min(p); % assuming `p` contains multiple temperatures?
    mintemp(month) = min(mintemp(month), temp); % update current month's min temp
  end
end