Average a section of a column in a table based on another column values

3 ビュー (過去 30 日間)
Gabi
Gabi 2022 年 4 月 19 日
編集済み: Gabi 2024 年 4 月 17 日
Hi,
I'm trying to average the values of a column(T3.value) coresponding to a different column in the same table (T3.index). T3.index goes form 0 to 10 in this example and output in another table with a single value for index and a single value for 'value'.
index average_value
0 x
1 y
. .
. .
10 z
i=T3.index
for i=1:max(i)
A(i)=mean(T3.value(i))
end

採用された回答

KSSV
KSSV 2022 年 4 月 19 日
編集済み: KSSV 2022 年 4 月 19 日
[c,ia,ib] = unique(T3.index) ;
N = length(c) ;
iwant = zeros(N,1) ;
for i = 1:N
iwant(i) = mean(T3.value(ib==i)) ;
end

その他の回答 (1 件)

Lola Davidson
Lola Davidson 2022 年 5 月 19 日
Hi Gabi,
We actually have several functions that can help with these "grouped calculations". In particular, I think groupsummary would be the easiest thing to use here:
T_means = groupsummary(T3,'index','mean');

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by