MATLAB: I have data for five different years, I need to separate each year separately? what’s the best possible way? I tried using datnum command..

date and time function

displaytime = datenum(time)-732313 I used this code and it gives me the data for all five years but I need the data for each year separately.

Best Answer

you should not use datenum but datevec as then the year is stored in the first column
timeVector =datevec(time);
timeYear = timeVector(:,1);
possibleYears = unique(timeYear);
datePerYear = cell(numel(possibleYears));
for ii = possibleYears
datePerYear{ii} = time(timeYear ==ii);
end
Related Question