Results 1 to 2 of 2

Math Help - Multiplying layers of a 3D matrix

  1. #1
    Newbie
    Joined
    Mar 2009
    Posts
    11
    Awards
    1

    Multiplying layers of a 3D matrix

    I am attempting to multiply each layer of a 2x2x4 matrix together. i.e. the first layer will be (:,:,1)...therefore Z(:,:,1)=X(:,:,1)*Y(:,:,1)...and so on until i reach the fourth layer.
    The for loop is a simple way of visualising this problem, but Im trying to speed up the code by vectorising and im at a loss as to how to go about this.
    Could someone be as kind as to point me in the right direction? Any further questions/ discussion are very welcome.


    X = rand(2,2,4)
    Y = rand(2,2,4)
    Z = zeros(2,2,4)

    for i = 1 : 4
    Z(:,:,i) = X(:,:,i)*Y(:,:,i)
    end

    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4

    Re: Multiplying layers of a 3D matrix

    Quote Originally Posted by p123nky View Post
    I am attempting to multiply each layer of a 2x2x4 matrix together. i.e. the first layer will be (:,:,1)...therefore Z(:,:,1)=X(:,:,1)*Y(:,:,1)...and so on until i reach the fourth layer.
    The for loop is a simple way of visualising this problem, but Im trying to speed up the code by vectorising and im at a loss as to how to go about this.
    Could someone be as kind as to point me in the right direction? Any further questions/ discussion are very welcome.


    I could be wrong, but I don't think you are going to significantly improve on that, but you could try asking on a specialised Matlab forum such as: Newsreader - MATLAB Central
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Multiplying Fractions
    Posted in the Algebra Forum
    Replies: 7
    Last Post: January 12th 2011, 09:07 AM
  2. Multiplying in GF(2)
    Posted in the Number Theory Forum
    Replies: 4
    Last Post: February 8th 2010, 11:20 AM
  3. Multiplying CIS
    Posted in the Pre-Calculus Forum
    Replies: 4
    Last Post: November 5th 2009, 03:08 AM
  4. Replies: 4
    Last Post: October 9th 2009, 01:38 PM
  5. Analytical solution of diffusion equation for two layers
    Posted in the Differential Equations Forum
    Replies: 0
    Last Post: April 30th 2009, 01:32 AM

Search Tags


/mathhelpforum @mathhelpforum