How to use just one output out of a function with several outputs in an equation?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a function with three outputs depending on x. I want to use one of these three say B(x) in an equation:
function [ A,B,C ] = f( x )
Equation=1+x+B(x)
How do I have to code the equation? what I want to have is something like this (does not work):
Equation=1+x+f(B(x))
0 comentarios
Respuestas (1)
Jan
el 11 de Nov. de 2017
Editada: Jan
el 11 de Nov. de 2017
You have to do this in two lines:
[~, B] = f(x);
Equation = 1 + x + B(x);
Of course you could write a function, which extracts a certain output only, but this is less clear:
function X = SelectOutput(N, Fcn, varargin)
[Out{1:N}] = Fcn(varargin{:});
X = Out{N};
end
Then:
Equation = 1 + x + SelectOutput(2, f(x));
I don't think, that this is an advantage.
2 comentarios
Jan
el 12 de Nov. de 2017
I cannot follow you. This code is unclear already:
function [ A,B,C ] = f( x )
Equation=1+x+B(x)
Why does "B" appear in the output, when it is used inside the function? Where do A and C come from?
Then "b=@(x) 3*x" seems to be completely unrelated. Please start from scratch and explain, which problem you try to solve. Append this information by editing the original question.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!