Problem 3. Find the sum of all the numbers of the input vector
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);
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).
can i get the answer?
Easy to solve. But how to reach better result???
good usage of ans
vecsum doesn't work in my 2018b software and I can't find vecsum in my documentation. Where is it?
y=sum(x) is not working
It's easy. A good problem to start for beginners!
this was fun and challenging
simple and sweet
not too difficult
I was originally confused by the assertion code but I understand now.
piece of cake!
really beginner friendly problem!
Solution CommentsShow comments
Problem Recent Solvers43285
More from this Author96
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!