[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: structfun: more than one output argument
From: |
Thorsten Meyer |
Subject: |
Re: structfun: more than one output argument |
Date: |
Tue, 19 Jan 2010 19:18:40 +0100 |
User-agent: |
Mozilla-Thunderbird 2.0.0.22 (X11/20090706) |
Jaroslav Hajek wrote:
> I should note that that the iscell (varargout{1}) is not sufficient to
> check for the uniform output case. Consider
> cellfun (@(x) {x}, {1, 2, 3}, "uniformoutput", true) - the result is
> still a cell.
> I pushed a different solution that really checks for the option, and
> also replaced the loop by a second cellfun call
As structfun is defined now, it is still possible to pass additional
cell arguments down to cellfun, e.g.:
structfun(@(x,y) x.^2+y, struct("a", 1, "b", {1,2}), {3},
"uniformoutput", false)
In your patch you have
uo_str = "uniformoutput";
nargs = length (varargin);
if (nargs >= 2 && strcmpi (varargin{1}, uo_str))
uniform_output =varargin{2};
elseif (nargs >= 4 && strcmpi (varargin{3}, uo_str))
uniform_output =varargin{4};
endif
which will not catch the "uniformoutput" in this case.
Are these additional cell arguments an unwanted feature or should the
above lines in structfun be replaced by something like:
index = strcmpi (varargin, uo_str);
if any(index)
uniform_output = varargin{find(index)(end)};
endif
regards
Thorsten