フィルターのクリア

Help calculating values from a table into a loop

1 回表示 (過去 30 日間)
Nina Perf
Nina Perf 2022 年 4 月 28 日
編集済み: Nina Perf 2022 年 4 月 29 日
Hi,
I have the following table T, where there are 2 different timepoints, for 2 different birds, 3 trials per day.
I want to calculate the timepoint 1 and 2, bird 1 and 2, pre and post trials (1 to 3) sum of value1, and sum of value 2 (like the code bellow).
However, I want to do this in a loop/function that wouln't require manual change of numbers. Can you help?
timepoint1_bird1_pre_trials = sum(T.value1(1:3))
timepoint2_bird1_pre_trials = sum(T.value1(7:9))
timepoint1_bird1_post_trials = sum(T.value1(4:6))
timepoint2_bird1_post_trials = sum(T.value1(10:12))

採用された回答

Cris LaPierre
Cris LaPierre 2022 年 4 月 28 日
編集済み: Cris LaPierre 2022 年 4 月 28 日
I would do this (untested)
sumTbl = groupsummary(T,["timepoint","bird","day"],'sum',"value1")
The result will be a table identifying each group and the sum of the corresponding group's value1 column.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by