Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Barry Shaw

Posts: 32
Registered: 2/16/12
Using @times or @prod with cellfun
Posted: Feb 20, 2013 12:05 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic 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?



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.