Contain outputs of function in one table(?)
4 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Nobel Mondal
on 5 May 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 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!