MATLAB: Not sure why I get a ‘output argument “….” (and maybe others) not assigned during call to [function name]’

functions

So I'm trying to write a function that works out the area of a triangle using:
function triangle = tri_area(b,h)
0.5*b*h
end
However, when I call the function in the command window using
area = tri_area(2,3)
, it says 'Output argument "triangle" (and maybe others) not assigned during call to "tri_area". '
I'm not sure why this comes up. If I remove the assignment of the tri_area function to triangle, I get a 'too many output arguments' error. There's obviously something with my code that Matlab doesn't like.

Best Answer

function triangle = tri_area(b,h)
triangle = 0.5*b*h ;
%^^^^^^^^^------ missed it!
end
doc function % please read it
Note: Don't name a variable area (it will shadow in-built function area()).