MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreOpportunities for recent engineering grads.

Apply TodayFind the sum of all the numbers of the input vector x.

Examples:

Input x = [1 2 3 5] Output y is 11

Input x = [42 -1] Output y is 41

14489 correct solutions
7400 incorrect solutions

Last solution submitted on Jul 27, 2016

23 players like this problem

2 Comments

Md.Farhad Hassan
on 25 Jul 2016 at 10:21

can anyone please help me to find out the where is the mistake, i am a new learner .........

Atsushi Ueno
on 25 Jul 2016 at 10:56

You have to define a function vecsum() like:
function y = vecsum(x)
y=0;
for x= 0:1:10
y=x+y;
end
end
because your answer is executed by calling function in test suite below. The function's name is decided by problem creater.

1 Comment

Pim van der Sluis
on 23 May 2016

This solution works.

1 player likes this solution

1 Comment

lis coffey
on 14 Jul 2016 at 12:06

unable to find the sum of all numbers in input vector, so the test set is correct. I make my solution: ' function y = vecsum(x) y = sum(x); end ' smaller?
Thanks
http://www.fixithere.net/sky-customer-service/

1 player likes this solution

1 Comment

Sierra McGee
on 13 Nov 2015

Yay! I got it right! Omg I'm so happy!

1 Comment

Sierra McGee
on 13 Nov 2015

What does this solution mean. In other words, can someone explain the solution step-by-step.

1 Comment

Yan Xu
on 22 Apr 2015

Good question!

1 player likes this solution

4 Comments

Show
1 older comment

VIVEK RUHELA
on 14 Nov 2014

why y=sum(x) is wrong. Still I made the same function on MATLAB software and it runs and give correct answer. Can anybody tell me whats going on......

Tim
on 14 Nov 2014

The "y=" is missing from "y=sum(x)".

VIVEK RUHELA
on 15 Nov 2014

@Mr. Tim . Atleast You give me positive reply.Thanks a lot.Can I further talk to you regarding MATLAB CODY Guidence..

Tim
on 19 Nov 2014

Sure, ok.

1 Comment

Carlos Pavon
on 16 Jun 2014

Bien Javier

1 Comment

fert
on 22 Feb 2014

y = sum(x)
x=[1 2 3 5]
is not that true, i am confused.

1 Comment

Andrew Newell
on 7 Jun 2013

This solution is just for a laugh - the test suite is pretty weak!

4 players like this solution

3 Comments

HaveF
on 17 Dec 2012

although ans trick can make the code short... but I don't like it...

Lajos
on 10 May 2014

I agree with HaveF.

Barry Becker
on 21 Nov 2015

Not to mention that it doesn't even run

1 Comment

greatordinary
on 3 Mar 2012

there is definitely something wrong with cody.I am getting 'Undefined function 'cody.verifyCode' for input arguments of type 'char'.' for my solution

1 Comment

Jeff
on 1 Feb 2012

Why isn't nansum(x) a solution?

1 player likes this solution

2 Comments

TAB
on 23 Jun 2012

Test for vactor
x = [1 4;3 4]
It will add columns only.

Ozan Gunaydin
on 22 Sep 2014

Problem is finding the sum of all numbers in an input vector, so the test set is correct.

8 Comments