I am trying to calculate mean of all the columns in my matrix. Help me please?

조회 수: 3 (최근 30일)
I am really new to coding and this might seem like a basic question. I am trying to calculate means of individual columns in my matrix and I want to run a loop to do that.
eg.
5 6 6 7 8 9 5 5 3 2 5 7 3 9 8 8 0 7 7 7 8 8 4 4
Basically I want the answers to be in the format
4 6.75 6.125..........
thanks

채택된 답변

meihua
meihua 2013년 8월 2일
>> a=[1 2 3; 1 2 3]
a =
1 2 3
1 2 3
>> mean(a,1)
ans =
1 2 3
The help section is extremely useful. You might consider using that first.
  댓글 수: 2
Rishav
Rishav 2013년 8월 5일
What if I have 5 columns,but I only want to find the means for columns first till the end. I say end because 5 could be 6,7,8,9, etc etc.
Jan
Jan 2013년 8월 5일
No, 5 could not be 6,7,8,9. 5 is 5. Please rephrase the question, if this guess does not match your needs:
m = mean(a(1:5, :), 1)

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

추가 답변 (0개)

카테고리

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