Using the mean function

조회 수: 10 (최근 30일)
Ryan
Ryan 2013년 4월 18일
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
Cedric
Cedric 2013년 4월 18일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

the cyclist
the cyclist 2013년 4월 18일
편집: the cyclist 2013년 4월 18일
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.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by