フィルターのクリア

Simple logic error I can't figure out

2 ビュー (過去 30 日間)
Mike Beacham
Mike Beacham 2014 年 7 月 15 日
コメント済み: Star Strider 2014 年 7 月 15 日
Hey, I'm making a quick file for telling if a given date is in DST or not. It's telling me
Operands to the || and && operators must be convertible to logical scalar values.
I don't know why I'm getting this.
For input values, I'm using
month =
7
5
2
day =
12
12
12
Date2 =
'2014-07-12 19:06:10'
'2014-05-12 19:06:20'
'2014-02-12 19:06:30'
My 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)
today = str2double(Date2(9:10));
if ((DOW == 2) && (today > 8))
DST = true;
elseif ((DOW == 3) && (today > 9))
DST = true;
elseif ((DOW == 4) && (today > 10))
DST = true;
elseif ((DOW == 5) && (today > 11))
DST = true;
elseif ((DOW == 6) && (today > 12))
DST = true;
elseif ((DOW == 7) && (today > 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)
today = str2double(Date2(4:5));
if ((DOW == 2) && (today < 2))
DST = true;
elseif ((DOW == 3) && (today <3))
DST = true;
elseif ((DOW == 4) && (today <4))
DST = true;
elseif ((DOW == 5) && (today <5))
DST = true;
elseif ((DOW == 6) && (today <6))
DST = true;
elseif ((DOW == 7) && (today <7))
DST = true;
else
DST = false;
end
end
end
else
DST = false;
end
Thanks!

採用された回答

Star Strider
Star Strider 2014 年 7 月 15 日
Try single operators for ‘|’ and ‘&’.
  2 件のコメント
Mike Beacham
Mike Beacham 2014 年 7 月 15 日
Thank you! What's the difference?
Star Strider
Star Strider 2014 年 7 月 15 日
My pleasure!
The double operators are ‘short circuit’ logical operators, and have special requirements. The single operators (for example or) perform simple logic operations.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by