3

例如,我想做一些事情,例如:

A=4:20;
find(A>5)(2) % want to access the 2nd element of the index array returned by find
4

1 回答 1

3

是的,这在不同的情况下相当 频繁地 出现,单行答案是。对于您的情况,是这样的:subsref

subsref(find(A>5),struct('type','()','subs',{{2}}))

更清洁的解决方案使用未记录的builtin

builtin('_paren',find(A>5),2)

作为丑陋语法或未记录功能的替代方法,您可以定义一个小函数,如下所示,

function outarray = nextind(inarray,inds)
outarray = inarray(inds);

或内联函数:

nextind = @(v,ii) v(ii);

并称其为nextind(find(A>5),2). subsref如果您正在执行线性索引(而不是下标),这比更干净而且更好。

于 2013-10-10T20:53:07.787 回答