>> a = [2,3,4;6,7,8]
a =
2 3 4
6 7 8
>> mean(a)
ans =
4 5 6
where [4 5 6]
is the mean for each column
How can I get the mean for each row?
In my example, I would expect [3;7]
Compute the mean of the elements of the vector x . If x is a matrix, compute the mean for each column and return them in a row vector. If the optional argument dim is given, operate along this dimension. The optional argument opt selects the type of mean to compute.
Description. M = mean( A ) returns the mean of the elements of A along the first array dimension whose size does not equal 1. If A is a vector, then mean(A) returns the mean of the elements. If A is a matrix, then mean(A) returns a row vector containing the mean of each column.
To extract an entire row or column, use the colon : operator like this, octave#:#> X(1,:) This will extract the first row of the matrix X. In this notation, the : operator refers to all the elements in the specified row or column. To change some elements of a matrix, simply reassign their values.
From http://www.mathworks.co.uk/help/techdoc/ref/mean.html:
For matrices,
mean(A,2)
is a column vector containing the mean value of each row.
In Octave it's the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With