Finding the dates surrounding a day
Info
This question is closed. Reopen it to edit or answer.
Show older comments
I have an array of dates for the solstices and equinoxes for several years. I have a vector of days. All dates/days are in matlab serial format. I need to see where a day falls between the dates for the solstices and equinoxes so that day can be labeled with a season:winter, spring, etc. I am leaning with using a case switch for the month. I then compare the years with another case switch. This code is UGLY. How can I do this in an elegant way befitting the elegance of MATLAB?
1 Comment
Oleg Komarov
on 3 Mar 2011
Post the code even if it's ugly.
You could use histc to redistribute dates among the seasonal buckets. The problem is how do you determine solstices and equinoxes dates. If you have them, then just a simple call to histc would solve the problem!
Answers (1)
Oleg Komarov
on 3 Mar 2011
Smt like this, once you have dates for equinoxes and solstices:
% First date 20-Mar-2004 06:49:00
equinox = [732026.284028,732119.039583,732212.687500,732302.529167,...
732391.522917,732484.281944,732577.932639,732667.774306,...
732756.768056,732849.518056,732943.168750,733033.015278,...
733122.004861,733214.754167,733308.410417,733398.255556,...
733487.241667,733579.999306,733673.655556,733763.502778,...
733852.488889,733945.239583,734038.887500,734128.740972,...
734217.730556,734310.477778,734404.131250,734493.984722,...
734582.972917,734675.719444,734769.377778,734859.229167,...
734948.218056,735040.964583,735134.617361,735224.466667,...
735313.459722,735406.211111,735499.863889,735589.715972,...
735678.706250,735771.452083,735865.103472,735954.960417,...
736043.947917,736136.693056,736230.347222,736320.200000,...
736409.187500,736501.940278,736595.597917,736685.447222,...
736774.436111,736867.183333,736960.834722,737050.686111];
% Check where it belongs to
[c,bin] = histc(now,equinox + 1/86400);
% Season: winter = 0, spring = 1, summer = 2, autumn = 3
season = mod(bin/4,1)*4;
1 Comment
Roderick
on 27 Jul 2011
This question is closed.
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!