I am struggling with my Matlab homework.
I have a datetime array called "date" and two arrays (X and Y) of the type double containing measurements for each time step.
I have to do the following task:
Select all time steps where both X AND Y are larger than their respective Z value. Store the dates of these time steps in a new variable. Name it 'C'
Z and Y are 52584x1 double vectors and date is a vector of the format 52584x1 datetime (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)
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.