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).

 Respuesta aceptada

Matt J
Matt J el 15 de Jul. de 2013
Editada: Matt J el 15 de Jul. de 2013

0 votos

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 comentarios

ricardo gunawan
ricardo gunawan el 15 de Jul. de 2013
my bad i'm really careless about var
anyway thx matt
Jan
Jan el 15 de Jul. de 2013
@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.

Iniciar sesión para comentar.

Más respuestas (1)

VELDANDI THARUN
VELDANDI THARUN el 10 de En. de 2020

0 votos

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

Categorías

Etiquetas

Preguntada:

el 15 de Jul. de 2013

Respondida:

el 10 de En. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by