Hi. I have an 738x2 catalog that contains days (0,1,2..etc) and earthquake magnitudes. I need to to find the magnitudes per day using a bin width i.e 2.1- 3, 3-4, 4-5, 5-6 and to store them in this format: 2.1-3 3-4 4-5
0 .... .... ....
Any help? Bellow, I attach my catalog. 1 .... .... ....

2 件のコメント

Jan
Jan 2021 年 3 月 2 日
編集済み: Jan 2021 年 3 月 2 日
I do not understand, which format you want. What does the ... mean?
Anna Sidiropoulou
Anna Sidiropoulou 2021 年 3 月 2 日
Days Magnitude bins
2.1-3 3-4 4-5 5-6
0 34 12 0 1
1 23 34 2 3
2 47 25 3 3

サインインしてコメントする。

 採用された回答

Cris LaPierre
Cris LaPierre 2021 年 3 月 2 日
編集済み: Cris LaPierre 2021 年 3 月 2 日

0 投票

A little creativity with groupsummary will get you the data you want. It allows you to group your data by day and by user-defined bin edges, each applied to just the corresponding table variables.
eq = readtable("days_magnitudes.txt");
eqT = groupsummary(eq,{'Var1','Var2'},{'none',[1 3 4 5 6]},'IncludeEmptyGroups',true,'IncludeMissingGroups',true)
eqT = 468x3 table
Var1 disc_Var2 GroupCount ____ _________ __________ 0 [1, 3) 56 0 [3, 4) 32 0 [4, 5) 2 0 [5, 6] 1 1 [1, 3) 61 1 [3, 4) 6 1 [4, 5) 0 1 [5, 6] 0 2 [1, 3) 37 2 [3, 4) 15 2 [4, 5) 1 2 [5, 6] 1 3 [1, 3) 21 3 [3, 4) 5 3 [4, 5) 0 3 [5, 6] 0
If you want the output to be a matrix with a row for each data, and a column for each bin, you can do that in the following way.
out = [unique(eq.Var1), reshape(eqT.GroupCount,4,[])']
out = 117×5
0 56 32 2 1 1 61 6 0 0 2 37 15 1 1 3 21 5 0 0 4 15 1 0 0 5 12 0 0 0 6 11 2 0 0 7 12 4 0 0 8 12 1 0 0 9 6 0 0 0

3 件のコメント

Anna Sidiropoulou
Anna Sidiropoulou 2021 年 3 月 2 日
Thank you, but I have a 2015 version. So any alternative for groupsummary ?
Cris LaPierre
Cris LaPierre 2021 年 3 月 2 日
You'll need alternatives for much of the code, as readtable will behave differently, and strings were not yet supported. You might be able to use findgroups and splitapply (introduced in R2015b), perhaps in conjunction with discretize (introduced in R2015a). Sorry, but I don't have a 2015 version installed to test it for you.
Any chance you can update? Or use MATLAB Online?
Anna Sidiropoulou
Anna Sidiropoulou 2021 年 3 月 3 日
Thank you, it worked!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSeismology についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by