MATLAB function syntax [closed]
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this questionI'm trying to learn MATLAB now; I tried a simple step, factorial function.
factorial.m
:
function result = factorial (m)
if m == 1
result = m;
else
result = m .* factorial(m.-1);
end
and then call it like this:
x = 2;
f = factorial (x)
but all I get is an error:
Missing variable or function.
- You have a syntax error, in the second line there shouldn't be a
.
after the 2ndm
- The
if
should be in a separate line from the function declaration.
精彩评论