matlab "arrayfun" function <p>Consider the following function, which takes a gray image (2D matrix) as input:</p> <pre><code>function r = fun1(img) r = sum(sum(img)); </code></pre> <p>I'm thinking of using <code>arrayfun</code> to process a series of images(3d matrix), thus eliminating the need for a <code>for</code> loop:</p> <pre><code>arrayfun(@fun1, imgStack); </code></pre> <p>But <code>arrayfun</code> tries to treat every element of <code>imgStack</code> as an input to <code>fun1</code>, the result of the previous operation also being a 3D matrix. How can I let <code>arrayfun</code> know that I want to repeat <code>fun1</code> only on the 3rd dimension of <code>imgStack</code>?</p> <p>Another question, does <code>arrayfun</code> invoke <code>fun1</code> in parallel?</p>