MATLAB Answers

Vector and matrix average

3 views (last 30 days)
matt noman
matt noman on 8 Feb 2020
Answered: Image Analyst on 9 Feb 2020
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 Comments

stozaki
stozaki on 9 Feb 2020
a=[2.4,2,3.4,4.5,5.63];
ave_a = mean(a);

Sign in to comment.

Answers (2)

stozaki
stozaki on 9 Feb 2020
a=[2.4,2,3.4,4.5,5.63];
ave_a = mean(a);

  0 Comments

Sign in to comment.


Image Analyst
Image Analyst on 9 Feb 2020
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

  0 Comments

Sign in to comment.

Sign in to answer this question.

Products


Translated by