Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以在 Matlab 中定义一个带有函数处理程序的函数作为参数?
我试过了
function x = name(@f,gh)
但我收到一条错误消息,指出“@”处的语法无效。
您不能使用涉及@函数定义的语法。匿名函数句柄可以完成这项工作:
@
function x = SO_Example(h,gh) x = h(gh);
您可以按如下方式调用该函数:
SO_Example(@(a)a.^2 , 2) ans = 4
或者像这样:
h = @(a)a.^2; SO_Example(h,2) ans = 4
请参阅评论以获取更多解释