开发者

MATLAB function syntax [closed]

开发者 https://www.devze.com 2023-02-21 22:08 出处:网络
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
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

精彩评论

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