Vector and matrix average

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 comentarios

Star Strider
Star Strider el 8 de Feb. de 2020
stozaki
stozaki el 9 de Feb. de 2020
a=[2.4,2,3.4,4.5,5.63];
ave_a = mean(a);

Iniciar sesión para comentar.

Respuestas (2)

stozaki
stozaki el 9 de Feb. de 2020

0 votos

a=[2.4,2,3.4,4.5,5.63];
ave_a = mean(a);
Image Analyst
Image Analyst el 9 de Feb. de 2020

0 votos

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

Categorías

Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 8 de Feb. de 2020

Respondida:

el 9 de Feb. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by