MATLAB: I am trying to get this function to work properly. I am wanting it to add together given values. What is wrong with the syntax? Thank you.

errorMATLABsyntax error

function result = findSum(a,b)
result = a + b
a=3
b=4

Best Answer

function result = findSum % no need for input because they are defined inside the function
a=3; % have to be defined before usage
b=4;
result = a + b;
end
or if you want to give a and b as inputs then see Kevin's comment
result = findSum(a,b) % function call
function result = findSum(a,b) %function definition
result = a + b;
end