I have a function that takes an image as an argument, and the result is a label and an estimate. Sometimes I want to quickly test an array (s) of images, and the most convenient way I know for this is to use arrayfun. This is great for getting shortcuts created by my function, but I would really like for the output to have a list of cells [label score].
arrayfun
[label score]
I could write a wrapper around my function that captures both values and returns them as a matrix of cells and then calls that wrapper inside arrayfun, but it looks like it's a pretty common idiom, that there should be a way to work with multiple return values more conveniently. Here? (Perhaps a standard convenience function already exists that can do this? As an opposite deal...)
deal
You can get your output as two matrices using the built-in syntax:
[A, B, ...] = arrayfun(fun, S, ...);
For instance:
function [y,z]=foo(x) y= x*x; z = x + 10; end
And then run the function:
[A,B] = arrayfun( @foo, magic(5))