如何将函数存储在MATLAB中的变量? [英] How to store a function in a variable in MATLAB?
本文介绍了如何将函数存储在MATLAB中的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
y(x)= x + 2
存储在一个变量中。 是否有任何方法可以保存 y = x + 2
,并以 y(x)
的形式访问?例如, y(2)
?
解决方案
=http://www.mathworks.com/help/matlab/matlab_prog/anonymous-functions.html =nofollow>匿名功能是您要找的内容:
>> y = @(x)x + 2;
>> y(2)
ans =
4
Let's say I want to store the function y(x) = x + 2
in a variable.
Is there any way to save y = x + 2
, and access as y(x)
? For example, y(2)
?
解决方案
An anonymous function is what you're looking for:
>> y = @(x) x+2;
>> y(2)
ans =
4
这篇关于如何将函数存储在MATLAB中的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文