Find values per day using a bin width.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Anna Sidiropoulou
il 2 Mar 2021
Commentato: Anna Sidiropoulou
il 3 Mar 2021
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 Commenti
Risposta accettata
Cris LaPierre
il 2 Mar 2021
Modificato: Cris LaPierre
il 2 Mar 2021
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)
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,[])']
3 Commenti
Cris LaPierre
il 2 Mar 2021
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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Seismology in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!