개발자 뺚
[Cody] Problem 106. Weighted average 본문
Given two lists of numbers, determine the weighted average as follows
Example
[1 2 3] and [10 15 20]
should result in
33.3333 (1*10 + 2*15 + 3*20)/3
function y = weighted_average(x,w)
[row, col] = size(x);
sum = 0;
for i = 1:col
sum = sum + x(i) * w(i);
end
y = sum / col;
end
'Solution > MATLAB' 카테고리의 다른 글
[Cody] Problem 44944. Convert from Fahrenheit to Celsius (0) | 2023.08.23 |
---|---|
[Cody] Problem 128. Sorted highest to lowest? (0) | 2023.08.22 |
[Cody] Problem 44943. Calculate Amount of Cake Frosting (0) | 2023.08.22 |
[Cody] Problem 2447. Musical Note Interval 1 - Diatonic Scale (21) | 2023.08.22 |
[Cody] Problem 1. Times 2 - START HERE (21) | 2023.08.22 |