Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the mean of rows of a matrix in Octave?

>> 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]

like image 933
B Seven Avatar asked Jan 31 '12 19:01

B Seven


People also ask

How do you find the mean of an octave?

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.

How do you find the mean of a matrix?

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.

How do I extract a row from a matrix in octave?

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.


1 Answers

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.

like image 171
NPE Avatar answered Sep 28 '22 03:09

NPE