多步骤匿名功能 [英] multiple step anonymous functions

查看:69
本文介绍了多步骤匿名功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常复杂的函数,我想将其编写为匿名函数.

I have a rather complicated function the I would like to write as an anonymous function.

它看起来像这样:

function Answer = MatlabFunction(x)
a=4*x;
b=sin(a);
c=cos(b);
Answer = c;

但是我不知道如何将其放入匿名函数中.有没有一种方法可以将其编写为几个级联函数?

I don't know how to put this into an anonymous function however. Is there a way to do this without writing it as several cascading functions?

推荐答案

有两种方法:

或者,您将函数MatlabFunction保存在Matlab路径上,并将匿名函数定义为

Either, you save your function MatlabFunction on the Matlab path, and define your anonymous function as

myFun = @MatlabFunction;

或者,您直接将函数定义为

Or, you define the function directly as

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

这篇关于多步骤匿名功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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