필터 지우기
필터 지우기

How to calculate the average of a cell array?

조회 수: 47 (최근 30일)
Ashfaq Ahmed
Ashfaq Ahmed 2023년 8월 7일
답변: Les Beckham 2023년 8월 7일
Hi, I have a cell array like this -
T = {[10, 1, 30], [15, 2, 10], [20, 3, 20]}
T = 1×3 cell array
{[10 1 30]} {[15 2 10]} {[20 3 20]}
I want to calculate the mean of T in a way that the result is a 1x3 double. And the result is,
T = [15, 2, 20]
It means the result should average the values of its position. (10+15+20)/3 = 15
Thank you!!

채택된 답변

Voss
Voss 2023년 8월 7일
T = {[10, 1, 30], [15, 2, 10], [20, 3, 20]}
T = 1×3 cell array
{[10 1 30]} {[15 2 10]} {[20 3 20]}
M = vertcat(T{:})
M = 3×3
10 1 30 15 2 10 20 3 20
meanT = mean(M,1)
meanT = 1×3
15 2 20

추가 답변 (1개)

Les Beckham
Les Beckham 2023년 8월 7일
T = {[10, 1, 30], [15, 2, 10], [20, 3, 20]}
T = 1×3 cell array
{[10 1 30]} {[15 2 10]} {[20 3 20]}
A = vertcat(T{:}) % make an array from the elements of the cell array by stacking them
A = 3×3
10 1 30 15 2 10 20 3 20
m = mean(A) % average the columns
m = 1×3
15 2 20

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by