chooseargs

版本 1.0.0.0 (2.0 KB) 作者: Adam Gripton
Allows direct, inline return of any combination of arguments and indices to a function.
150.0 次下载
更新时间 2012/2/16

查看许可证

C = chooseargs(f,argidx,idxc,[f_inputs])

chooseargs allows direct selection of any
combination of arguments to a function f
that has the following form:

[y1,y2,...,yM] = f(f_inputs)

and outputs a cell C such that:

C{k} == y[argidx(k)](idxc{k}).

Comma-separated multidimensional
indices are allowed if the entries of
the cell idxc are themselves cells.

Example:

A=magic(3)

[y1,y2]=max(A);

%returns y1=[8,9,7], y2=[1,3,2]

chooseargs(@max,1,[2,3],A)
%returns y1([2,3])=[9,7]
chooseargs(@max,1,{1,[2,3]},A)
%returns y1(1,[2,3])=[9,7]
chooseargs(@max,2,[],A)
%returns y2=[1,3,2]
chooseargs(@max,2,{[1,1],[2,3]},A)
%returns y2([1,1],[2,3]) = [3,2;3,2]
chooseargs(@max,[1,2],{{[1,1],[2,3]},[]},A)
%returns {y1([1,1],[2,3]),y2}
% = {[9,7;9,7],[1,3,2]}

引用格式

Adam Gripton (2024). chooseargs (https://www.mathworks.com/matlabcentral/fileexchange/35115-chooseargs), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2011b
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Function Creation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.0.0.0