MATLAB: How to compute a column with seasons (1 to 4) based upon a date

columnseason

I want to compute a column with seasons (1 to 4) based upon a date?
For instance: 1-12-2018, month=1, so that means season 2?
Any tips for my problem?
Thomas

Best Answer

datevec is useful in your case. You may proceed something like this:
dt = datevec('1-12-2018') ;
month = dt(:,1) ;
month gives you all the months..now use logical indexing..
seasons = zeros(size(month)) ;
seasons(month==1) = 1 ;