フィルターのクリア

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.
  1 件のコメント
Mike Beacham
Mike Beacham 2014 年 7 月 15 日
Awesome, thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by