Using a function as an input to another
古いコメントを表示
I have a function with two output arguments. I'm trying to pass it as an input to another function where I will need both outputs of the first function.
This is just a minimal example. The two functions:
function [X y] = M(d)
X = d;
[~,Y] = d;
end
function [A B] = N(a)
A = 2*a;
B = 3*a;
end
Basically, I want the following two lines to produce the same output
[a b] =N(3)
M(N(3))
1 件のコメント
madhan ravi
2018 年 10 月 22 日
add comments to your code so that its easier to understand what you are trying to do
採用された回答
その他の回答 (1 件)
madhan ravi
2018 年 10 月 22 日
編集済み: madhan ravi
2018 年 10 月 22 日
function [X y] = M(d) %like this not sure what you want to do but a guess
X = d;
[~,Y] = d;
[A B] = @N
function [A B] = N(a)
A = 2*a;
B = 3*a;
end
end
7 件のコメント
kor vec
2018 年 10 月 22 日
madhan ravi
2018 年 10 月 22 日
give a short example with numbers
kor vec
2018 年 10 月 22 日
Walter Roberson
2018 年 10 月 22 日
You are not passing in a function: you are passing in a vector.
madhan ravi
2018 年 10 月 23 日
Thank you sir Walter
Walter Roberson
2018 年 10 月 23 日
[A B] = @N
would try to assign a handle to the function N to both A and B, but would fail because the operation of taking a handle to a function does not return multiple outputs.
madhan ravi
2018 年 10 月 23 日
Oh ok sir thank you for clarifying
カテゴリ
ヘルプ センター および File Exchange で Startup and Shutdown についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!