MATLAB: How to perform cumulative adding of data by month and then plot it by year

by monthcumsumcumulativedatemonthmonthly dataper monthsum

I have data in a 8500×3 matrix – columns being year, month, day of each earthquake (all are in numerical representation – e.g. 1985 01 23). The data is in chronological order, with oldest first. As the number of earthquakes varies per day, the number of rows dedicated to each day/month/year changes.
I need to make a plot of cumulative number of earthquakes per month. I know I have to assign a one to every earthquake, but my problem comes in the cumulative adding. How do I add the data from one month in a given year to the next month? The problem arises due to the changing year as well.
Example of data:
[1985 01 01; 1985 01 12; 1985 01 14; 1985 01 25; 1985 03 02; 1985 06 16; 1985 06 18; 1985 11 09; 1986 01 01; 1986 01 30] …
I hope I explained this easily.
Thanks, Gareth

Best Answer

I don’t understand your Question and your ‘desired output’. This accumulates the total number in each month, and then the cumulative sum:
Seism = [1985 01 01; 1985 01 12; 1985 01 14; 1985 01 25; 1985 03 02; 1985 06 16; 1985 06 18; 1985 11 09; 1986 01 01; 1986 01 30];
SeismDN = datenum([Seism(:, 1:2) ones(size(Seism,1),1) zeros(size(Seism,1),3)]);
[SeismU,~,Idx] = unique(SeismDN,'stable');
SeisHist = accumarray(Idx,1);
Result = [str2num(datestr(SeismU, 'yyyy mm')) cumsum(SeisHist)]
Result =
1985 1 4
1985 3 5
1985 6 7
1985 11 8
1986 1 10