set value of a variable according to date
Ältere Kommentare anzeigen
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.
I see https://www.mathworks.com/help/matlab/matlab_prog/compare-dates-and-time.html to set up the order on datetime variables.
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 Kommentare
Mathieu NOE
am 30 Nov. 2020
hello
you have to convert to "numerical" date format using datenum
so your code would be now :
d1 = datenum('01-March-2020');
d2 = datenum('31-May-2020');
if d1 < datenum(date) < d2
seasons = 'spring'
end
alpedhuez
am 30 Nov. 2020
Rik
am 30 Nov. 2020
d1 < datenum(date) < d2
This will not do what you think it does. Read the warning mlint is giving you.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Dates and Time finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!