和/或if语句之间的层次结构 [英] Hierarchy between and / or in an if statement

查看:113
本文介绍了和/或if语句之间的层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为data的文件,其中有一个Data.ensemble部分,其前几行如下所示:

I have a file called data, within which there is a part Data.ensemble of which the first few lines look as following:

                Year Month Day Hour Min Temp
0   1635    1   2009    12  10  22  36  16.28
0   1635    2   2009    12  10  22  37  17.25
0   1635    3   2009    12  10  22  38  16.97
0   1635    4   2009    12  10  22  39  16.69
0   1635    5   2009    12  10  22  40  17.42

我想在12月的每小时0、20、30和40分钟提取温度.我在编码时遇到了麻烦.这就是我正在尝试的:

I want to extract the temperature in December on minute 0, 20, 30 and 40 every hour. I have trouble coding this. This is what I am trying:

Month = 12;
Minute = [0 20 30 40];

if Data.ensemble(:, 5) == Month & (Data.ensemble(:, 8) == (Minute(1) | Minute(2) | Minute(3) | Minute(4)))
    Temperature = Data.ensemble(:, 10)
end

这似乎不会创建Temperature,我希望它只是复制整个色谱柱,而不仅仅是复制正确分钟的温度.而且,我不太确定方括号是否在和/或之间使用正确的层次结构.必须始终是12月(12)和分钟(0或20或30或40)中的分钟.

This doesn't seem to create Temperature, and I expect it's just gonna copy the entire colomn, not just the temperature for the correct minutes. Moreover, I am not quite sure the brackets really use the right hierarchy between and / or. It has to always be december (12) and on of the minutes (0 or 20 or 30 or 40).

推荐答案

您可以使用如果要使用if else语句,则需要一个for循环来单独检查每一行.

If you want to use an if else statement you need a for loop to check each row individually.

这篇关于和/或if语句之间的层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆