@(t) 在 Matlab 中是什么意思? [英] @(t) mean in Matlab?
问题描述
正如标题所暗示的,鉴于以下上下文,@(t) 在 Matlab 中究竟是什么意思?computeNumericalGradient 是一个函数,cofiCostFunc 也是一个接收大量参数的函数.问题是@(t) 到底对 cofiCostFunc 函数做了什么?
As the title suggest, what exactly does @(t) mean in Matlab given the context below? computeNumericalGradient is a function and cofiCostFunc is also a function that takes in a bunch of parameters. The question is what exactly is the @(t) doing to the cofiCostFunc function?
computeNumericalGradient( ...
@(t) cofiCostFunc(t, Y, R, num_users, num_movies, ...
num_features, lambda), [X(:); Theta(:)]);
推荐答案
@(t)
就是所谓的 匿名函数.@(t)
因此将返回一个句柄给一个函数,该函数接受一个变量t
.基本上,它是一个接受一个参数 t
的函数.其余参数先前已在您的工作区中定义.
@(t)
is what is known as an anonymous function. @(t)
will thus return a handle to a function that takes in one variable t
. Basically, it's a function that takes in one parameter, t
. The rest of the parameters are defined previously in your workspace.
您在这里所做的是 computeNumericalGradient
的第一个参数接受一个 函数,其中 t
是一个由您定义的变量.因此,您的 computeNumericalGradient
接受两个参数:
What you are doing here is that the first parameter to computeNumericalGradient
takes in a function where t
is a variable that is defined by you. As such, your computeNumericalGradient
takes in two parameters:
- 一个像以前一样定义的匿名函数.
- 具有两个相互连接的列向量的单个一维向量 - 第一列是
X
,第二列是Theta
.
- An anonymous function that is defined like before.
- A single 1D vector with two column vectors concatenated with each other - The first column is
X
, and the second column isTheta
.
作为旁注,如果您要这样做:
As a sidenote, if you were to do this:
func = @(t) cofiCostFunc(t, Y, R, num_users, num_movies, num_features, lambda);
因此,您可以通过执行 func(t)
来调用此函数,其中 t
是您想要的与手头函数相关的任何变量.因此,代码将简化为:
You would thus call this function by doing func(t)
, where t
is whatever variable you want that is relevant to the function at hand. The code would thus simplify to:
computeNumericalGradient(func, [X(:); Theta(:)]);
我不熟悉你在这里做什么,所以你必须弄清楚上下文.
I'm not familiar with what you're doing here, so that context will have to be figured out by you.
这篇关于@(t) 在 Matlab 中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!