开发者

MATLAB function syntax [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. 开发者_开发百科

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 question

I'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.


  1. You have a syntax error, in the second line there shouldn't be a . after the 2nd m
  2. The if should be in a separate line from the function declaration.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜