MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   多步骤匿名功能 (https://www.labfans.com/bbs/showthread.php?t=23881)

poster 2019-12-10 20:48

多步骤匿名功能
 
我有一个相当复杂的函数,我想将其编写为匿名函数。

看起来像这样:

function Answer = MatlabFunction(x) a=4*x; b=sin(a); c=cos(b); Answer = c; 我不知道如何将其放入匿名函数中。有没有一种方法可以不将其编写为几个级联函数呢?



[B]回答:[/B]

有两种方法:

您可以将函数MatlabFunction保存在Matlab路径上,然后将匿名函数定义为

myFun = @MatlabFunction; 或者,您直接将函数定义为

myFun = @(x)cos(sin(4*x));

[url=https://stackoverflow.com/questions/3673030]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 23:29

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.