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.

回答(1 个)

dpb
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
>>

类别

Help CenterFile Exchange 中查找有关 Earthquake Engineering 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by