필터 지우기
필터 지우기

Contain outputs of function in one table(?)

조회 수: 3 (최근 30일)
Christian
Christian 2015년 5월 4일
답변: Nobel Mondal 2015년 5월 5일
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

채택된 답변

Nobel Mondal
Nobel Mondal 2015년 5월 5일
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개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by