matlab - 在数据集中查找一个月的最低温度
问题描述
我已经制作了一个函数,可以从给定月份和年份的特定时间的数据集中提取所有温度。
看起来像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 的所有温度。
不要把我的程序都当回事,这只是一个粗略的写法,让自己对它的外观有一个想法。也许它澄清了我的问题。
解决方案
您可能正在寻找这样的东西:
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
推荐阅读
- sql-server - 将两个不同表中的项目计数到一个结果表中
- json - Python/JSON:当在 json 文件中找不到特定的东西时,我想去它
- r - 当要求大量组合时,R combn 失败(即使内存就足够了)
- swift - 如何为可选实例属性赋值?
- lisp - lisp 宏是否曾经评估它们的表达式,或者它们只是进行转换?
- javascript - 从打字稿中的地图检索值时,map.get 不是函数
- json - 底层连接已关闭:接收时发生意外错误。从 Azure Powershell Runbook 使用 Invoke-RestMethod 时
- javascript - 反应上下文菜单onClick不适用于多个上下文菜单
- python - 在不同长度上并行循环
- php - 如何将此 SQL 转换为准备好的语句?