Vector and matrix average

조회 수: 4 (최근 30일)
matt noman
matt noman 2020년 2월 8일
답변: Image Analyst 2020년 2월 9일
how do I find the average of ths function in matlab
a=[2.42,3.4,4.5,5.63]
b=6
I want to find the average by adding all the numbers in a and b together and then divide them by 6 how would I write that code
  댓글 수: 2
Star Strider
Star Strider 2020년 2월 8일
stozaki
stozaki 2020년 2월 9일
a=[2.4,2,3.4,4.5,5.63];
ave_a = mean(a);

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

답변 (2개)

stozaki
stozaki 2020년 2월 9일
a=[2.4,2,3.4,4.5,5.63];
ave_a = mean(a);

Image Analyst
Image Analyst 2020년 2월 9일
Nearly everyone would use mean, like they've told you. However if you want to do it like you said, using the sum and number of elements in the two variables, you'd do this
a=[2.4,2,3.4,4.5,5.63]
b = 6
theSum = sum(a) + sum(b)
numberOfElements = numel(a) + numel(b)
theMean = theSum / numberOfElements

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by