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

1 回表示 (過去 30 日間)
Jesus Cruz Lopez
Jesus Cruz Lopez 2020 年 11 月 29 日
編集済み: dpb 2020 年 11 月 29 日
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 Center および File ExchangeEarthquake Engineering についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by