java 调用octave_Octave中的函数句柄

您的初始函数 twodcomp :您不能将输出变量(在 = 之前)命名为与函数名称相同(在 = 之后) .

然后,如果要使用 @ 表示法分配匿名函数(MATLAB docs,Octave docs),仍然可以传递所需的输入 .

所以重写它像:

% Include empty parentheses after a function name to make it clear which is the output

function output = twodcomp()

% Not sure why you're assigning this function to a struct, but

% still give yourself the ability to pass arguments.

% I'm assuming you want to use the output variable,

% and not reuse the main function name (again)

output.twoDperp = @(x,y) perp(x,y);

end

使用第二个函数,您只需要在输出参数之前删除 twoDperp . 在您的问题中,您说明了文档中的预期语法,但之后没有遵循它...

function [vmag, vangle] = perp(x,y)

W = hypot(y,x);

vmag = y/W;

vangle = x/y;

end

现在这些可以像这样使用:

% Deliberately using different variable names to make it clear where things

% overlap from the function output. twodcomp output is some struct.

myStruct = twodcomp();

% The output struct has the field "twoDperp" which is a function with 2 outputs

[m, a] = myStruct.twoDperp(1,2);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值