Using the mean function

7 visualizaciones (últimos 30 días)
Ryan
Ryan el 18 de Abr. de 2013
I have a matrix that is 16x8. I need to take the mean value of all of the values from the 3rd to the 8th column. How could I do this?
  1 comentario
Cedric
Cedric el 18 de Abr. de 2013
What ave you tried so far?
I would recommend the official documentation:
Under MATLAB, you could get..
  • PDF labeled "MATLAB Primer" and study chapters 2 and 5.
  • PDF labeled "Mathematics", and train to have a good mastery of chapters 1 and 9.
  • PDF labeled "Programming Fundamentals" and have a look at the table of content so you can use it as a reference later.
The first two references will teach you how to index blocks of matrices. It's a good investment of your time to train a bit indexing. I am sure that after no more than 20-30 minutes spent on these references, you will know how to extract the 3rd to the 8th column of your matrix. Once you are able to do this, refer to the following example:
M = [1 2 3; 4 5 6] ;
mean(M(:)) % Provides the mean of all elements in M.
Type
doc mean
and you will see that it is applied along a specific dimension (that can be specified). Then type
M(:)
to see what it does and understand why we pass it to MEAN.

Iniciar sesión para comentar.

Respuestas (1)

the cyclist
the cyclist el 18 de Abr. de 2013
Editada: the cyclist el 18 de Abr. de 2013
If you need the mean of each column, then
>> M = mean(x(:,3:8))
If you need the mean of the values in those columns, all together, then one way is
>> subMatrix = x(:,3:8);
>> M = mean(subMatrix(:));
where x is your original matrix.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by