Problem 3. Find the sum of all the numbers of the input vector
Solution Stats
Problem Comments

49 Comments
If x is 3x3 (or 3x3x3) or similarly shaped vector, sum(x) doesn't automatically add up all of the numbers in the entire vector. You need a loop to go through each dimension of x to get the sum of every element.
James, a vector traditionally denotes a 1xd or dx1 matrix (with d > 1). If d = 1, we tend to call that a scalar.
Firstly you'd need to vectorize the elements as in suppose x is 3x3 or any size mxp, let y=x(:); now you can find the sum by employing the function sum,i.e,sum(y);
What is the size of vector....is it [1*n] or [n*m]
Well said, Rohan.
I'm only commenting for the badge
Why is the solution larger when I call it a single? Additionally, how can I make my solution:
' function y = vecsum(x)
y = sum(x);
end '
smaller?
solved it on first try
You don't need write x=[1 2 3 5]. He ask us write a function. So, it should be y=sum(x).
Easy
thank you
nice
yay
nice
very easy
yes
can i get the answer?
Easy to solve. But how to reach better result???
y=sum(x)
good
Great Problem!
good usage of ans
Nice one.
great problem
vecsum doesn't work in my 2018b software and I can't find vecsum in my documentation. Where is it?
y=sum(A)
y=sum(x) is not working
Easy!
It's easy. A good problem to start for beginners!
good
good question
this was fun and challenging
simple and sweet
good practice
Nice!!
nice practice
easy
nice
good practice
Very easy
not too difficult
I was originally confused by the assertion code but I understand now.
not bad
easy problem
pretty easy
piece of cake!
too ez
really beginner friendly problem!
gg ez
Solution Comments

1 Comment
Easy starter question!

1 Comment
very good problem

1 Comment
not hard

1 Comment
Easy function to write.

1 Comment
This one is easy

2 Comments
I don't understand why all of this is done in the function file.
How else would you proceed?

1 Comment
Easy but my solution might not be optimal

1 Comment
good basic problem

1 Comment
good Problem!

1 Comment
great

1 Comment
Still new to matlab and I didn't realise that you can add elements in a vector, at least I am learning new things

1 Comment
Hardest one yet

1 Comment
I like this task

1 Comment
It's easy when you're turning it into a column vector

2 Comments
idk
good

1 Comment
How can the leading solution size be 7?

1 Comment
good idea

1 Comment
one of the simplest task.

4 Comments
Please remove this is a misleading solution.
Hmmm, are you sure this is the leading solution?
who can tell me what is this????/!!
Ha! Small tricks.

2 Comments
Come on, this one is so easy
I am using either for loop or sum command (twice) but it saying error. Any clue?

1 Comment
lets go

1 Comment
I used the "sum" function to solve this problem really quickly.

2 Comments
Why doesn't it work?
function y=vecsum(x)
y=symsum(x(i),i,1,size(x));
end
Because you are doing it wrong!
You should check the basis of 'sum' topic in the help.
Here you go: https://www.mathworks.com/help/matlab/ref/sum.html?searchHighlight=sum%20vector&s_tid=doc_srchtitle

1 Comment
very easy

1 Comment
nice

1 Comment
easy

1 Comment
good job

1 Comment
Nice!

1 Comment
This user appears to have gamed the system, with fraudulent "likes" of this unremarkable solution submitted by 'sockpuppet' accounts. —DIV

1 Comment
easy :)

3 Comments
can anyone please help me to find out the where is the mistake, i am a new learner .........
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.
What is your code Sir?
If you write your code here, I can say where is the mistake.

1 Comment
This solution works.

1 Comment
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/skycustomerservice/

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

1 Comment
What does this solution mean. In other words, can someone explain the solution stepbystep.

1 Comment
Good question!

4 Comments
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......
The "y=" is missing from "y=sum(x)".
@Mr. Tim . Atleast You give me positive reply.Thanks a lot.Can I further talk to you regarding MATLAB CODY Guidence..
Sure, ok.

1 Comment
Bien Javier

3 Comments
y = sum(x)
x=[1 2 3 5]
is not that true, i am confused.
You haven't stated the *Function* name, input values and output values. Without them the code from the site cannot check your code.
Secondly you've declared X after you wanted to run a function with it.
The program will read:
Sum of X equals Y. X equals Zero or Not a Number, therefore Y is Zero or Not a Number. Next line, X is [Array]. Okay, X is [Array].
Also good practice to end your functions with a semicolon ;
;)
You haven't stated the *Function* name, input values and output values. Without them the code from the site cannot check your code. Secondly you've declared X after you wanted to run a function with it. The program will read: Sum of X equals Y. X equals Zero or Not a Number, therefore Y is Zero or Not a Number. Next line, X is [Array]. Okay, X is [Array]. Y is still 0 or NaN. Also good practice to end your functions with a semicolon ;

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

3 Comments

6 Comments
although ans trick can make the code short... but I don't like it...
I agree with HaveF.
Not to mention that it doesn't even run
WOCAO!!!!!!!!!! this is a trcik..........
nice solution
nhu cai dac cau

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

1 Comment
Why isn't nansum(x) a solution?

2 Comments
Test for vactor
x = [1 4;3 4]
It will add columns only.
Problem is finding the sum of all numbers in an input vector, so the test set is correct.
Problem Recent Solvers42346
Suggested Problems

Remove all the words that end with "ain"
1856 Solvers

Determine Whether an array is empty
731 Solvers

Matlab Basics  Convert a row vector to a column vector
564 Solvers

807 Solvers

642 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!