matlab-tree icon indicating copy to clipboard operation
matlab-tree copied to clipboard

treefun* functions support variable output arguments

Open ejrx opened this issue 8 years ago • 0 comments

Hi,

While using your library, I came across the need to have treefun return multiple values for a given tree (similar to how cellfun or arrayfun work).

An example of how it works:

function [a,s] = add_sub_one(val)
    a = val+1; s = val + 1;
end
>> disp(t.tostring)
 1 
++-+
|  |
2  3
>> [ta,ts] = t.treefun(@add_sub_one);
>> disp([ta.tostring ts.tostring])
 2     0
++-+  ++-+
|  |  |  |
3  4  1  2

Note that this does not break the API for these functions, so single-return-value functions can be called the same as they have been.

I've tested on R2014b and R2015b.

ejrx avatar Sep 23 '16 23:09 ejrx