Matlab:直接访问函数的特定返回值
我想使用一个函数的特定返回值,并将其作为一个线性函数传递给另一个函数 问题是我不能简单地访问返回值,比如someFunction(x,y,z){2}或[2]或(2), 例如:Matlab:直接访问函数的特定返回值,matlab,function,variables,Matlab,Function,Variables,我想使用一个函数的特定返回值,并将其作为一个线性函数传递给另一个函数 问题是我不能简单地访问返回值,比如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(re
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 = @(r, idx) r{idx}
#now get first returned argument
itemgetter(regexpi(str,'[a-z]+','match'), 1)
有关更多信息和其他可能的方式,请查看。谢谢!这太好了!我建议你分两行来做。这样您的代码将更具可读性。