[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Handling variable number of output arguments in multi-level function cal
From: |
Jose |
Subject: |
Handling variable number of output arguments in multi-level function calls |
Date: |
Fri, 12 Dec 2014 14:02:53 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 |
Dear community.
I often face the situation in which a function (say f1) calls another
function internally (say f2) whose number of outputs depends on the
number of outputs requested from the upper calling function f1.
Something like this
--->
function [o1,o2]=f1(varargin)
...
if nargout==1
[o1]=f2(varargin{:});
elseif nargout==2
[o1,o2]=f2(varargin{:});
endif
...
endfunction
<---
This example shows how I am handling the problem of calling f2 with the
right number of output arguments. I suspect that this is something that
other users also face often, and I also suspect that there might be a
better way to handle this (one can imagine easily how the code gets
cluttered in case there are many output arguments).
Does somebody know a more elegant (and perhaps more efficient?) way to
handle this?
Thanks in advance and kind regards,
José
- Handling variable number of output arguments in multi-level function calls,
Jose <=