mean of parts of an array in octave
===

I have two arrays.  One is a list of lengths within the other.  For example

    zarray = [1 2 3 4 5 6 7 8 9 10]

and

    lengths = [1 3 2 1 3]

I want to average (mean) over parts the first array with lengths given by the second.  For this example, resulting in:

    [mean([1]),mean([2,3,4]),mean([5,6]),mean([7]),mean([8,9,10])]

I am trying to avoid looping, for the sake of speed.  I tried using mat2cell and cellfun as follows

    zcell = mat2cell(zarray,[1],lengths);
    zcellsum = cellfun('mean',zcell);

But the cellfun part is *very* slow.  Is there a way to do this without looping or cellfun?
