# averages of a matrix

4 Ansichten (letzte 30 Tage)
Anthony Campuzano am 8 Jun. 2015
Given variable A that contains a row vector of values, and variable w that contains a row vector of weights, compute the weighted average of A and store the result into variable W_A
Examples: Inputs A = [1 2 3], w = [4 6 1] Output W_A = (1*4 + 2*6 + 3*1)/3 = 6.3333
Inputs A = [5.4 3 2.1 7], w = [1 1 0.5 1]
Output W_A = (5.4*1 + 3*1 + 2.1*0.5 + 7*1)/4 = 4.1125
I don't think the question is asking about weighted avg properly, so you can ignore that. I am just trying to figure out the proper code that would be capable of solving the example problems above...
##### 1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Salaheddin Hosseinzadeh am 8 Jun. 2015
Anthony
Be careful what you want. Star Strider mentioned a good point.

Melden Sie sich an, um zu kommentieren.

### Antworten (2)

Star Strider am 8 Jun. 2015
The weighted mean is the sum of the product of the values times the weights divided by the sum of the weights:
WgtdMean = sum(A.*w)/sum(w);
See the Wikipedia article: Weighted arithmetic mean.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Salaheddin Hosseinzadeh am 8 Jun. 2015
Hi Anthony,
output = mean(A.*B)
That's all
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by