Using the mean function

8 次查看(过去 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