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 Exchange에서 Time 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