weighted average for an array

Hey
Can someone please tell me how to use weighted average for an array

5 commentaires

Adam
Adam le 29 Juil 2019
What do you mean by 'how to use it'? How you use it depends entirely on the context and generally you know what you want to use it for before you calculate it in the first place!
Anisha Varughese
Anisha Varughese le 29 Juil 2019
I did not ask 'what should I use weighted average for.' I was talking about the code or syntax which i can use.
Adam
Adam le 29 Juil 2019
That's why I asked what do you mean by 'how to use it'. If you mean how you calculate it rather than how you use it then simply
sum( weights .* array )
will give you the answer, assuming weights is another array of length equal to array
Adam Danz
Adam Danz le 29 Juil 2019
There isn't enough information in your question to form a useful answer. Weighted averages can be used in many ways. From what we currently know, you have a weighted average and you're asking how to use it or you're asking for code that uses weighted averages. The question is unclear.
dpb
dpb le 29 Juil 2019
sum(weights.*array)
is ok if sum(weights) == 1; the general rule is
sum(weights.*array)/sum(weights)

Connectez-vous pour commenter.

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by