Using the mean function

3 views (last 30 days)
Ryan
Ryan on 18 Apr 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 Comment
Cedric
Cedric on 18 Apr 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.

Sign in to comment.

Answers (1)

the cyclist
the cyclist on 18 Apr 2013
Edited: the cyclist on 18 Apr 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.

Community Treasure Hunt

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

Start Hunting!