function chaining when one function has multiple outputs
Similar question has been asked before, but I would ask the question in a more specific manner. If the function in the input end has more than one output, there will be the error ‘Not enough input arguments’. Is there a neat way to make chained function out of that situation?
f(g) % only the first output of g is kept as input for f
function [x, y] = g()
x = 1;
y = 2;
end
function out = f(x, y)
out = x+y;
end
Storing the outputs of the first function in two variables could be a solution, but I like to see how chaining could be done in this kind of scenario for the sake of learning.
[x, y] = g();
f(x, y)Similar question has been asked before, but I would ask the question in a more specific manner. If the function in the input end has more than one output, there will be the error ‘Not enough input arguments’. Is there a neat way to make chained function out of that situation?
f(g) % only the first output of g is kept as input for f
function [x, y] = g()
x = 1;
y = 2;
end
function out = f(x, y)
out = x+y;
end
Storing the outputs of the first function in two variables could be a solution, but I like to see how chaining could be done in this kind of scenario for the sake of learning.
[x, y] = g();
f(x, y) Similar question has been asked before, but I would ask the question in a more specific manner. If the function in the input end has more than one output, there will be the error ‘Not enough input arguments’. Is there a neat way to make chained function out of that situation?
f(g) % only the first output of g is kept as input for f
function [x, y] = g()
x = 1;
y = 2;
end
function out = f(x, y)
out = x+y;
end
Storing the outputs of the first function in two variables could be a solution, but I like to see how chaining could be done in this kind of scenario for the sake of learning.
[x, y] = g();
f(x, y) chained_function, function_chaining, function_composition MATLAB Answers — New Questions