Weighted average - MATLAB Cody - MATLAB Central

Problem 44156. Weighted average

Difficulty:Rate

Compute the weighted average Y, of the vector A, given the weight vector W.

The weighted average is the sum of the dot product of A and W, normalized by the sum of W.

Example 1:

A = [10 15 20 10];
W = [ 1  1  1  1];
Y = 13.75

Example 2:

A = [  10    15   20   10];
W = [0.25  0.25 0.25 0.25];
Y = 13.75

Example 3:

A = [10 15 20 10];
W = [ 2  4  4  2];
Y = 15

Solution Stats

44.36% Correct | 55.64% Incorrect
Last Solution submitted on Mar 06, 2025

Problem Comments

Solution Comments

Show comments
PIVlab surpasses 100K all-time File Exchange downloads
During the past twelve months, PIVlab, a MATLAB Community Toolbox for particle...
2
4
LLMs with MATLAB updated to support the latest OpenAI Models
Large Languge model with MATLAB, a free add-on that lets you access...
2
4

Problem Recent Solvers107

Community Treasure Hunt

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

Start Hunting!
Go to top of page