Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab:直接访问函数的特定返回值_Matlab_Function_Variables - Fatal编程技术网

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

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

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

问题是我不能简单地访问返回值,比如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 = @(r, idx) r{idx}


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

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

谢谢!这太好了!我建议你分两行来做。这样您的代码将更具可读性。