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

查看:1387
本文介绍了@(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) 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天全站免登陆