Average of Column Values with Condition

Hello, all!
I'm currently trying to bin a large CTD data file and I know I must use a for loop to create the average values, but I'm not sure how to implement it. For example, I have about 100 lines of data for depth "2" that are 2.3455, 2.3434, 2.4532 and so on. I have this for depth 2 meters - 751 meters. I would like to average all the values together that begin with the same number (all of the "2"s, "3"s, etc.). Thanks in advance!

回答 (2 件)

Image Analyst
Image Analyst 2020 年 12 月 1 日

0 投票

Why not just set up edges and take the histogram? Then take the center bin value and multiply it by the count?
If you can't figure it out, let me know.

1 件のコメント

Jennifer Holifield
Jennifer Holifield 2020 年 12 月 1 日
To be honest, im not sure what you mean by setting up the edges. I am familiar with taking the histogram, but I'm stuck on how to limit it to similar values.

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

Jeff Miller
Jeff Miller 2020 年 12 月 1 日

0 投票

if your data are in a table, maybe you can use grpstats something like this:
tbl.IntDepth = trunc(tbl.depth); % assuming depth values like 2.3455, etc
avgs = grpstats(tbl,'IntDepth','mean','DataVars',{'depth'}); % to get the average depth within each range

カテゴリ

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

質問済み:

2020 年 12 月 1 日

回答済み:

2020 年 12 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by