Matlab:直接访问函数的特定返回值



我想使用一个函数的特定返回值,并将其作为单行传递给另一个函数。

问题是我不能简单地访问像someFunction(x,y,z){2}或[2]或(2)这样的返回值,例如:

regexpi(str,'[a-z]+','match') % returns a cell array, i just need the first match.(btw, ^ doesn't work in matlab?)

如果我想把regexpi()的第一个孩子传给myfun(),我想要的是:

myfun(regexpi(str,'[a-z]+','match')(1))

但我得到了一个错误:

Error: ()-indexing must appear last in an index expression.

有什么解决方法吗?谢谢!

不幸的是,它不能在 matlab 中完成,它只是不受支持。我所知道的唯一方法,在某种程度上是优雅的,是创建itemgetter(python中的ala itemgetter)。例如

itemgetter = @(r, idx) r{idx}

#now get first returned argument
itemgetter(regexpi(str,'[a-z]+','match'), 1)

有关更多信息和其他可能的方法,请查看此处。

最新更新