简体   繁体   English

如果循环查找值大于某个阈值的日期

[英]If loop to find date where values are bigger than certain threshold

I am struggling with my Matlab homework.我正在为我的 Matlab 作业而苦苦挣扎。

I have a datetime array called "date" and two arrays (X and Y) of the type double containing measurements for each time step.我有一个名为“date”的日期时间数组和两个 double 类型的数组(X 和 Y),其中包含每个时间步的测量值。

I have to do the following task:我必须执行以下任务:

Select all time steps where both X AND Y are larger than their respective Z value.选择 X 和 Y 都大于其各自 Z 值的所有时间步。 Store the dates of these time steps in a new variable.将这些时间步的日期存储在一个新变量中。 Name it 'C'将其命名为“C”

Z and Y are 52584x1 double vectors and date is a vector of the format 52584x1 datetime (dd.MM.yyyy hh:mm) Z 和 Y 是 52584x1 双向量,日期是格式 52584x1 日期时间 (dd.MM.yyyy hh:mm) 的向量

I tried:我试过:

%Some Dummy Data:
Y = 1:8:80
X = 2:4:40
t1 = datetime(2013,11,1,8,0,0)
t2 = datetime(2013,11,10,8,0,0)
date = t1:t2

Z = 8;

for i = length(date) 
    if X(i) > Z && Y(i) > Z
         C=date(i)
    end
end

I guess something is wrong with C=date(i)我猜C=date(i)

Thankful for any help!感谢您的帮助!

I guess what you need might be something like below:我想您需要的可能如下所示:

Z = 8;
for i = 1:length(date) 
    if X(i) > Z && Y(i) > Z
         C(end+1)= date(i);
    end
end

alternative : C = date((X>Z)& (Y>Z)) or C = date(min([X;Y],[],1) > Z) is a more efficient solution instead of using for loop替代方案C = date((X>Z)& (Y>Z))C = date(min([X;Y],[],1) > Z)是一种更有效的解决方案,而不是使用for循环

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM