Passing multiple outputs inside a function
Mostrar comentarios más antiguos
I have been trying to program a function that will evaluate another function:
function [result]=evaluate(second_function,x,y,z)
.
.
.
the problem arises when the second_function has multiple outputs:
function [a,b,c]=second_function(x,yz)
I am clueless as to how to pass each output to the calling function ("evaluate"), so that it can use them for further purposes. I am aware of the nargout function but then I am lost as to how to dynamically assign each output to, say, a vector containing each output in a different row:
function [result]=evaluate(second_function,x,y,z)
v(:)=second_function(x,y,z);
Of course, I could program second_function in a way that the multiple outputs would be compressed in a vector:
function [a]=second_function(x,y,z)
a(1)=...;
a(2)=...;
a(3)=...;
But that adds further complications to the rest of my code.
I have to clarify that second_function is different each time (user defined) and I want the program to dynamically evaluate it.
Respuesta aceptada
Más respuestas (1)
Paulo Silva
el 8 de Sept. de 2011
doc varargin
2 comentarios
Victor
el 8 de Sept. de 2011
Oleg Komarov
el 8 de Sept. de 2011
You can use varargout and store several outputs in a cell array and pass it to the second functions as out{:}, i.e. "unpacking" the content of the cell array.
Categorías
Más información sobre Variables en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!