set value of a variable according to date

조회 수: 1 (최근 30일)
alpedhuez
alpedhuez 2020년 11월 30일
답변: Rik 2020년 11월 30일
I have a table
date seasons
----------------------------------------
01-January-2020
02-January-2020
This date is "datetime" variable. I want to set the value of "seasons" like
if 01-March-2020 < date < 31-May-2020
seasons = (the value of the cell at the time of O1-March-2020)
end
I would like to understand how to write if conditions for datetime variable.
But I still do not see how I can refer to the value of the cell at the time of 01-March-2020
Thank you in advance.
  댓글 수: 3
alpedhuez
alpedhuez 2020년 11월 30일
Thank you.
Rik
Rik 2020년 11월 30일
d1 < datenum(date) < d2
This will not do what you think it does. Read the warning mlint is giving you.

댓글을 달려면 로그인하십시오.

채택된 답변

Rik
Rik 2020년 11월 30일
No need to convert to a numerical date:
d1 = datetime('01-March-2020');
d2 = datetime('31-May-2020');
date=datetime('10-March-2020');
if d1 < date && date < d2
seasons = 'spring'
end
seasons = 'spring'

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by