matlab忽略警告,如何优雅地忽略MATLAB函数的某些返回值?

shabbychef..

9

我写了一个第k个函数:

function kth = kthout(k,ffnc,varargin)

%% kthout: take the kth varargout from a func call %FOLDUP

%

% kth = kthout(k,ffnc,varargin)

%

% input:

% k which varargout to get

% ffnc function to call;

% varargin passed to ffnc;

% output:

% kth the kth argout;

% global:

% nb:

% See also:

% todo:

% changelog:

%

%% %UNFOLD

[outargs{1:k}] = feval(ffnc,varargin{:});

kth = outargs{k};

end %function

然后你可以打电话

val_i_want = kthout(3,@myfunc,func_input_1,func_input_2); %etc

你也可以像这样结束这个功能

func_i_want = @(varargin)(kthout(3,@myfunc,varargin{:})); %assuming you want the 3rd output.

之后你使用

val_i_want = func_i_want(func_input_1,func_input_2);

请注意,使用这样的匿名函数会产生开销,而这在我将要调用数千次的代码中不会发生.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值