Borrar filtros
Borrar filtros

Contain outputs of function in one table(?)

3 visualizaciones (últimos 30 días)
Christian
Christian el 4 de Mayo de 2015
Respondida: Nobel Mondal el 5 de Mayo de 2015
Hi there,
I wrote a function, which gives out 10 numbers as a result. Right now, I am containing the outputs like this
[a,b,c,d,e,f] = function(Inputvariables) ... which is a bit annoying
Is there a better way to cope with a function that has a lot of output variables?
Any help is much appreciated! Christian

Respuesta aceptada

Nobel Mondal
Nobel Mondal el 5 de Mayo de 2015
1. If your output variables all have equal number of rows, you indeed can use a 'table' datatype.
doc table
2. Otherwise, you could create a struct and define the output parameters as fields of that. This would require declaring single output variable at the function definition.
3. You could also store them in a cell-array and pass as the single output argument. However, this would require some indexing wrt the variables. So I might turn up saving the parameter names along.
function cellOutput = myFunc(inputArgs)
% Do something and collect outputs a, b, c
cellOutput{1,1} = 'a';
cellOutput{1,2} = a;
% and so on...
end

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by