matlab fcnchk 函数用法

fcnchk will not accept string expressions for FUN in a future release. Use anonymous functions for FUN instead.
fcnchk函数将会在以后的版本中删除,以后用匿名函数代替

fcnchk(FUN,...) returns an inline object based on FUN if FUN
is a string containing parentheses, variables, and math
operators.  fcnchk simply returns FUN if FUN is a function handle, 
or a MATLAB object with an feval method (such as an inline object). 
If FUN is a string name of a function (e.g. 'sin'), fcnchk returns a
function handle to that function.

fcnchk is a helper function for FMINBND, FMINSEARCH, FZERO, etc. so they
can compute with string expressions in addition to functions.

fcnchk(FUN,...,'vectorized') processes the string (e.g., replacing
'*' with '.*') to produce a vectorized function.

When FUN contains an expression then fcnchk(FUN,...) is the same as
INLINE(FUN,...) except that the optional trailing argument 'vectorized'
can be used to produce a vectorized function.

[F,ERR] = fcnchk(...) returns a struct array ERR. This struct is empty
if F was constructed successfully. ERR can be used with ERROR to throw
an appropriate error message if F was not constructed successfully.

简单点来说,如果将字符串传递给fcnchk函数,函数会返回inline函数(前提是这个字符串代表的函数你以经定义了)

例如我定义了一个矩形函数:

function z = rect(x)
x= abs(x); 
z = (x<1/2)*1.0 ;
z(find(x==1/2)) = 0.5;
end

上面的函数是一维的,如果我想定义一个二维的矩形函数怎么办呢?
我可以将字符串rect(x).*rect(y)传递到fcnchk函数里,会返回一个定义好了的inline函数func,可以理解为定义好了的函数句柄,

fun = 'rect(x).*rect(y)'
func = fcnchk(fun);

调用func函数,X,Y是函数的坐标

f = feval(func,X,Y);

如果想要指定输入参数的情况下,例如定义矩形函数的门宽,rect(x/w).*rect(y/w),
可以采用下面的形式

fun = 'rect(x/w).*rect(y/w)'
func = inline(fun,'x','y','w');

不过这个函数快要退出历史舞台了,还是去学匿名函数的用法吧😂
看到一个不错的参考资料,需要的朋友可以去看下:
http://pages.cs.wisc.edu/~cs310-1/modules/Programming/_More%20Advanced%20Functions/fcnchk%20Function/TopicDiscussion.html

觉得帮到您的朋友请赏个赞👍呗!

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值