首页 > 解决方案 > 在数据集中查找一个月的最低温度

问题描述

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

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

我现在想找到某个月份的最低温度,比如一月份,跨越多年。例如,如果我查看 1997 年至 2006 年之间的一月。现在我想要 1997 年至 2006 年之间一月的最低注册温度。

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

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 年并找到最低温度。然后对于下一个循环,它将经历 1997-2006 年的month 2. 然后应该重复直到第 12 个月。

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

不要把我的程序都当回事,这只是一个粗略的写法,让自己对它的外观有一个想法。也许它澄清了我的问题。

标签: matlabfor-loop

解决方案


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

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

推荐阅读