MATLAB: Simple logic error I can’t figure out

daylight savingserrorif elselogic

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!

Best Answer

Try single operators for ‘|’ and ‘&’.
Related Question