Dwadelfri
Dwadelfri

Reputation: 464

Matlab find x of weighted average

How to find the weighted average x? From graphing x(y) it looks to be around x=0.45?

y = [0.1 0.1 0.2 0.5 0.4 0.2]
x = [0.1 0.2 0.3 0.4 0.5 0.6]

One way to perhaps compute it would to find x where the area under the curve y(x) is half of the area under the whole curve. But how to write that in matlab?

Upvotes: 1

Views: 60

Answers (1)

Cris Luengo
Cris Luengo

Reputation: 60564

Assuming you intend y to be the weights, and you want to compute the weighted average of x, then the weighted average is simply

sum(x.*y) / sum(y)

Upvotes: 2

Related Questions