检查Matlab函数是否存在输入参数

Cia*_*lsh 2 matlab function

我正在尝试检查Matlab函数的输入,以查看用户是否忘记了它(在这种情况下这很容易).

如果用户没有提供,number_obs那么我想暂停程序并等待用户输入此信息.

其他一些StackOverflow帖子似乎建议使用,~exist但这似乎不起作用.任何人都可以在这里暗示我做错了吗?

function output=test(number_obs) 
if ~exist('number_obs'),
    number_obs=input('How many observations do you have in your experiments?')
end 
Run Code Online (Sandbox Code Playgroud)

Python等价物将是这样的:

def test(number_obs):
    if nummber_obs != None:
        output=raw_input('How many observations do you have in your experiments? :')
    return output
Run Code Online (Sandbox Code Playgroud)

Ste*_*eve 6

你可以用nargin做到这一点

function output=test(number_obs) 
if nargin<1
    number_obs=input('How many observations do you have in your experiments?')
end 
Run Code Online (Sandbox Code Playgroud)