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
Easy but my solution might not be optimal
good basic problem
good Problem!
great
Still new to matlab and I didn't realise that you can add elements in a vector, at least I am learning new things
Hardest one yet
I like this task
It's easy when you're turning it into a column vector
idk
good
How can the leading solution size be 7?
good idea
ddd
one of the simplest task.
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.
你好骚啊
Come on, this one is so easy
I am using either for loop or sum command (twice) but it saying error. Any clue?
lets go
I used the "sum" function to solve this problem really quickly.
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
very easy
nice
easy
good job
Nice!
This user appears to have gamed the system, with fraudulent "likes" of this unremarkable solution submitted by 'sock-puppet' accounts. —DIV
easy :)
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.
This solution works.
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/
Yay! I got it right! Omg I'm so happy!
What does this solution mean. In other words, can someone explain the solution step-by-step.
Good question!
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.
Bien Javier
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 ;
This solution is just for a laugh - the test suite is pretty weak!
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..........
there is definitely something wrong with cody.I am getting 'Undefined function 'cody.verifyCode' for input arguments of type 'char'.' for my solution
GOOD
Why isn't nansum(x) a solution?
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.
300 Solvers
Integer Sequence - II : New Fibonacci
289 Solvers
403 Solvers
427 Solvers
Solve a System of Linear Equations
5423 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!