フィルターのクリア

Can I get multiple outputs using an anonymous function as an argument for another function?

3 ビュー (過去 30 日間)
So I've got a function FuseArrays that takes in a 2D cell array, applies a function to each cell, and then combines corresponding rows of the resulting array using a second function. So when I call it it looks like this:
rateVector = FuseArrays(burstInfoArray, @GetBurstMetrics, @(x) mean(x, 'omitnan'));
I'm running into a problem where I want to get the second output from GetBurstMetrics and apply the "fusing" function (the second one, the anonymous one) to the resulting array from the second output of GetBurstMetrics. Is there anyway that I can edit this line to replace @GetBurstMetrics with some kind of anonymous function syntax that will return only it's second output? Thank in advance!
EDIT: I have already tried simply [output1, output2] = FuseArrays....
This doesn't seem to have the desired effect, it seems to expect FuseArrays itself to have multiple outputs, as opposed to the argument functions.
  2 件のコメント
Rik
Rik 2018 年 8 月 30 日
This is blurring the line a bit between what a function is and what an input is. If you want the second output of that function, can't you use some intermediary function?
function out=get_second_output(in_handle)
[~,out]=in_handle();
end
John Jacoby
John Jacoby 2018 年 8 月 30 日
At first I read this and thought it would be really annoying to have to write a new function to get each output, but actually yeah I'm just going to write a GetOutput function and pass which number output I want as an argument. Thanks for the idea!

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2018 年 8 月 30 日
編集済み: Walter Roberson 2018 年 8 月 30 日
Unfortunately MATLAB does not provide any method to be able to capture anything other than the first output of a function in an expression. If you need to work with additional outputs then you need to write a function that assigns the output to a variable and returns the variable.
  1 件のコメント
John Jacoby
John Jacoby 2018 年 8 月 30 日
Ah that's too bad, but the commenter above gave me an idea for a pretty decent solution. Thanks for responding!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by