필터 지우기
필터 지우기

How do I perform cumulative adding of data by month and then plot it by year?

조회 수: 1 (최근 30일)
I have data in a 8500x3 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

채택된 답변

Star Strider
Star Strider 2016년 2월 11일
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
  댓글 수: 9
Gareth Maver
Gareth Maver 2016년 2월 12일
Basically there is another column with earthquake magnitude values in it - ranging from 2.0 up to about 5.0. How would I code to only count the earthquakes above value 3.0 for the cumulative sum?
Star Strider
Star Strider 2016년 2월 12일
This is how I would edit the original date and magnitude matrix:
datenms = datenum(bsxfun(@plus, [1985 01 01], [zeros(20,1) [1:20]' zeros(20,1)])); % Create Dates
Data = [datenms rand(20,1)*3.3+2]; % All Dates & Magnitudes
Data3 = Data(Data(:,2) > 3,:); % Select Magnitude > 3
If you wanted only the dates, in this example you would select ‘Data3(:,1)’.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Seismology에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by