Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: Using @times or @prod with cellfun
Replies: 2   Last Post: Feb 21, 2013 5:20 PM

 Search Thread: Advanced Search

 Messages: [ Previous | Next ]
 Barry Shaw Posts: 32 Registered: 2/16/12
Using @times or @prod with cellfun
Posted: Feb 20, 2013 12:05 PM
 Plain Text Reply

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?

Date Subject Author
2/20/13 Barry Shaw
2/21/13 Steven Lord
2/21/13 Bruno Luong

© The Math Forum at NCTM 1994-2016. All Rights Reserved.