Contain outputs of function in one table(?)
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposta accettata
Nobel Mondal
il 5 Mag 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
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!