필터 지우기
필터 지우기

Multiple logic outputs not working

조회 수: 1 (최근 30일)
Mike Beacham
Mike Beacham 2014년 7월 15일
댓글: Mike Beacham 2014년 7월 15일
Hi, I'm trying to get my logical outputs of (1/0) to match up for each value of a matrix I input and it's only giving me the last result. What do I need to change to get it to save each output?
Inputs:
month =
3
3
3
day =
12
12
12
year =
2014
2014
2014
Date2 =
'2014-03-12 19:06:10'
'2014-03-12 19:06:20'
'2014-03-12 19:06:30'
Code is as follows:
if (month > 3) & (month <11)
DST=true;
elseif ((month < 3) | (month > 11))
DST= false;
elseif (month == 3)
if (day > 14)
DST=true;
elseif (day < 8)
DST=false;
else
DOW = weekday(Date2,'yyyy-mm-dd');
if (DOW == 1)
DST=true;
elseif (DOW > 1)
if ((DOW == 2) & (day > 8))
DST = true;
elseif ((DOW == 3) & (day > 9))
DST = true;
elseif ((DOW == 4) & (day > 10))
DST = true;
elseif ((DOW == 5) & (day > 11))
DST = true;
elseif ((DOW == 6) & (day > 12))
DST = true;
elseif ((DOW == 7) & (day > 13))
DST = true;
else
DST = false;
end
end
end
elseif (month == 11)
if (day > 7)
DST=false;
else
DOW = weekday(Date2,'mm/dd/yyyy');
if (DOW == 1)
DST=false;
elseif (DOW > 1)
if ((DOW == 2) & (day < 2))
DST = true;
elseif ((DOW == 3) & (day <3))
DST = true;
elseif ((DOW == 4) & (day <4))
DST = true;
elseif ((DOW == 5) & (day <5))
DST = true;
elseif ((DOW == 6) & (day <6))
DST = true;
elseif ((DOW == 7) & (day <7))
DST = true;
else
DST = false;
end
end
end
else
DST = false;
end
Also, any suggestions for improvement are welcome. I'm new to this, hence the really basic coding.

채택된 답변

Sara
Sara 2014년 7월 15일
You need to wrap everything into a loop
DTS = false(3,1);
for i = 1:numel(month)
...your code
end
and use month(i), day(i), and so on.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by