@(t) 在 Matlab 中是什么意思? [英] @(t) mean in Matlab?

查看:175
本文介绍了@(t) 在 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:

  1. 一个像以前一样定义的匿名函数.
  2. 具有两个相互连接的列向量的单个一维向量 - 第一列是 X,第二列是 Theta.
  1. An anonymous function that is defined like before.
  2. A single 1D vector with two column vectors concatenated with each other - The first column is X, and the second column is Theta.

作为旁注,如果您要这样做:

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屋!

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