How can I count the number of times a specific year appears given an x amount of dates
조회 수: 1 (최근 30일)
이전 댓글 표시
I want to count the number of times a specific year appears in the coloumn "Date". (see csv file attachment)
Each date in the format mm/dd/YYYY represents an earthquake for a specific year. So if I want to know how many earthquakes occured in the year 1965, I think I should receive a total count of 339 earthquaks for the year 1965.
Can you please make the code as simple as posbile, I'm new to coding.
댓글 수: 0
답변 (1개)
dpb
2020년 11월 29일
편집: dpb
2020년 11월 29일
tEQ=readtable('database.csv');
uYr=unique(year(tEQ.Date));
nEq=histc(year(tEQ.Date),uYr);
tNEQ=table(uYr,nEq,'VariableNames',{'Year','Number EQ'});
results in
>> head(tNEQ)
ans =
8×2 table
Year Number EQ
____ _________
1965 339
1966 234
1967 255
1968 305
1969 323
1970 345
1971 386
1972 388
>> tail(tNEQ)
ans =
8×2 table
Year Number EQ
____ _________
2009 517
2010 560
2011 713
2012 445
2013 461
2014 480
2015 446
2016 469
>>
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Earthquake Engineering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!