Date: Feb 20, 2013 12:05 PM
Author: Barry Shaw
Subject: Using @times or @prod with cellfun


Hi

I was wondering if some could help. I think it's fairly straightforward.

>> a(:,:,1)={[2 5 5] [5 7 7];[3 8] [2 6]};
>> a(:,:,3)={[2 5 5] [5 7 7];[3 8] [2 6]};


This give
I want to multiply for example [2 5 5] and [2 5 5] to get [4 25 25]. I want to do this with all 4 elements. I've done this using

>> a(:,:,2) = cellfun(@times,a(:,:,1),a(:,:,3),'Uni',0);

>> a{1,1,2}

ans =

4 25 25

However, I want to generalise this, to multiplying more than 2 planes in the 3rd dimension. I've tried
>> a(:,:,2) = cellfun(@times,a(:,:,[1 3]),'Uni',0)
??? Error using ==> times
Not enough input arguments.

I've also tried
cellfun(@(x) prod(x,3), a(:,:,[1 3]), 'UniformOutput', 0).

But these are giving me errors, or not what I want.

Anybody help please?