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
madhan ravi 2018년 10월 22일
add comments to your code so that its easier to understand what you are trying to do

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2018년 10월 22일

0 개 추천

No, when a function has multiple outputs, the only way to capture them all is to use a real function and assign the results to variables. It is not possible in MATLAB to capture multiple outputs of a function inside an expression.

댓글 수: 1

kor vec
kor vec 2018년 10월 22일
Thanks. I guess I will have to work my way around it.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

madhan ravi
madhan ravi 2018년 10월 22일
편집: madhan ravi 2018년 10월 22일

0 개 추천

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
kor vec 2018년 10월 22일
Thanks for replying.
I have two functions (f1 and f2)
f1 is working as intended and has two output arguments.
f2 is supposed to have f1 as the first input the argument f2(f1,...)
I need to operate on both outputs of f1 inside f2 but can only access the first.
madhan ravi
madhan ravi 2018년 10월 22일
give a short example with numbers
kor vec
kor vec 2018년 10월 22일
[a b] = f1(1) = [2 3]
f2(f1(1)) = 2 % I want this to produce [2,3]
Walter Roberson
Walter Roberson 2018년 10월 22일
You are not passing in a function: you are passing in a vector.
madhan ravi
madhan ravi 2018년 10월 23일
Thank you sir Walter
[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
madhan ravi 2018년 10월 23일
Oh ok sir thank you for clarifying

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

태그

질문:

2018년 10월 22일

댓글:

2018년 10월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by