How do I find the average/mean of each row if the data has 150 rows and 3 columns?

1 回表示 (過去 30 日間)
Olivia Gilliam
Olivia Gilliam 2021 年 2 月 23 日
回答済み: David Hill 2021 年 2 月 23 日
A = 'measurements';
mean(A,2)
(This is what I have so far but it computes one value, when I need 1 row of 150 averages)

回答 (2 件)

Walter Roberson
Walter Roberson 2021 年 2 月 23 日
A = 'measurements';
That assigns the character vector ['m' 'e' 'a' 's' 'u' etc] to A, not the content of a variable named measurements.
%create some demonstration data
measurements = randi(10, 150, 3);
%now do the work
A = measurements; %not actually needed, could work directly on measurements
rowmeans = mean(A, 2)
rowmeans = 150×1
5.0000 6.3333 5.3333 2.3333 7.6667 6.3333 6.6667 6.3333 8.3333 6.3333

David Hill
David Hill 2021 年 2 月 23 日
If A=(150x3 matrix), then
b=mean(A,2);%will be a 150x1 column vector of the averages of each of the 150 rows
b=b';%transpose to 1x150 row vector.

カテゴリ

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