How can I count the number of times a specific year appears given an x amount of dates
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
dpb
am 29 Nov. 2020
Bearbeitet: dpb
am 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
>>
0 Kommentare
Siehe auch
Kategorien
Mehr zu Earthquake Engineering finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!