How can I count the number of times a specific year appears given an x amount of dates

1 view (last 30 days)
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.

Answers (1)

dpb
dpb on 29 Nov 2020
Edited: dpb on 29 Nov 2020
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
>>

Tags

Community Treasure Hunt

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

Start Hunting!