Matlab没有括号的调用函数 [英] Matlab Calling Functions without parentheses

查看:656
本文介绍了Matlab没有括号的调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



示例:

 清除xx 

我可以使用圆括号并使用变量名称传输字符串: c $ c>

如何在使用Google搜索解决方案时区分两种选择?

红利问题:如何将变量的内容放入不使用括号的调用中?具体而言,使用带有动态-o 文件名选项的mcc的构建脚本;用圆括号调用mcc也是可以接受的,但我不知道如何google,因此这个问题。



谢谢!

解决方案

当您调用不带括号的函数时,它被称为命令语法。以下是相关文件的三个链接:







  • 备注

    使用括号是st因为在使用命令语法时,您也无法从函数获取输出值。



    从上面的第三篇文档链接中,您可以看到消息阻止使用MATLAB时的命令语法。


    注意:虽然未加引号的命令语法很方便,但在某些情况下它可以被错误地使用而不会导致MATLAB产生错误。



    What is the correct name for the situation where a Matlab-script calls a function, but provides arguments without parentheses?

    Example:

    clear xx
    

    Alternatively, I could use parentheses and transfer a string with the variable name:

    clear('xx')
    

    How can I distinguish between both alternatives when googling for a solution?

    Bonus Question: How can I put the content of a variable into a call that is NOT using parentheses? Specifically, a build-script using mcc with a dynamic -o filename option; calling mcc with parentheses would also be acceptable, but I don't know how to google that, hence this question.

    Thank you!

    解决方案

    When you call a function without the brackets, it is called command syntax. Here are three links to relevant documentation:


    Bonus answer

    You cannot use a variable when using command syntax. From the docs:

    When calling a function using command syntax, MATLAB passes the arguments as character vectors.

    So it would work like so:

    abc = zeros(10); % Some matrix called abc
    mystring = 'abc' % A string containing the variable name
    % Option 1:
    clear('abc')     % Clears the variable abc
    % Option 2:
    clear abc        % As per above docs quote, interpreted as clear('abc')
    % Option 3:
    clear mystring   % As per option 2, interpreted as clear('mystring') so doesn't work
    % Option 4:
    clear(mystring)  % Interpreted as clear('abc') so works as expected
    

    When calling mcc as you suggest in the question, the tooltip shows you can in fact use function syntax, despite the documentation being entirely shown using command syntax.


    Notes

    Using brackets is standard practise in MATLAB, since you also cannot get output values from a function when using command syntax.

    Also from the 3rd docs link above, you can see a message discouraging the use of command syntax when using MATLAB.

    Caution: While the unquoted command syntax is convenient, in some cases it can be used incorrectly without causing MATLAB to generate an error.

    这篇关于Matlab没有括号的调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆