function y = weighted_average(x,w)
f=x.*y;
f=sum(f);
y=f/length(x);
end
is there any error. i submit and get WA(wrong answer).

 採用された回答

Matt J
Matt J 2013 年 7 月 15 日
編集済み: Matt J 2013 年 7 月 15 日

0 投票

Instead of
f=x.*y
shouldn't it be
f=x.*w
I can't see how you get any output at all, whether correct or incorrect. You should be getting an error message.

2 件のコメント

ricardo gunawan
ricardo gunawan 2013 年 7 月 15 日
my bad i'm really careless about var
anyway thx matt
Jan
Jan 2013 年 7 月 15 日
@ricardo: The error would have been obvious, when you read the error message. The description "I get WA(wrong answer" is cryptic.
Please run this code on your computer and examine the error messages. Using the debugger is a good idea also. But letting the forum solve your Cody challenges is not a resource friendly method for this game.

サインインしてコメントする。

その他の回答 (1 件)

VELDANDI THARUN
VELDANDI THARUN 2020 年 1 月 10 日

0 投票

function y = weighted_average(x,w)
y =(x*w.')/length(x)
end

カテゴリ

ヘルプ センター および File ExchangeTime Series Objects についてさらに検索

質問済み:

2013 年 7 月 15 日

回答済み:

2020 年 1 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by