将一个函数作为参数传递给另一个函数 [英] Passing a function as argument to another function

查看:184
本文介绍了将一个函数作为参数传递给另一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到一个像

sigma = 3*e-2
svmTrain(...,@(X,y)gaussianKernel(X,y,sigma),...);

这样的函数传递发生了什么,有人会解释吗?

What is going on with such a function passing, would someone explain ?

推荐答案

语法@(X,y) gaussianKernel(X, y, sigma)创建

The syntax @(X,y) gaussianKernel(X, y, sigma) creates an anonymous function by binding the third argument of this existing function guassianKernel(X, y, s) to specifically be the value sigma.

如果检查svmTrain函数签名,您会发现它允许传入一个函数,而该函数正是该匿名函数的去向.

If you inspect the svmTrain function signature, you'll see that it allows passing in a function, which is where this anonymous function is going.

这篇关于将一个函数作为参数传递给另一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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