Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: product 3D matrix with a vector
Replies: 7   Last Post: Jan 3, 2012 2:55 PM

 Search Thread: Advanced Search

 Messages: [ Previous | Next ]
 Paolo Tarpanelli Posts: 49 Registered: 1/9/06
Re: product 3D matrix with a vector
Posted: Jan 2, 2012 8:48 AM
 Plain Text Reply

"Nasser M. Abbasi" <nma@12000.org> wrote in message <jdsbie\$6cq\$1@speranza.aioe.org>...
> On 1/2/2012 7:12 AM, Paolo wrote:
> > Hello,
> >
> > I have 1 3D matrix like this
> > A(n,m,k)
> > and 1 vector like this
> > V(m,1)
> >
> > what I am trying to do is the sum of the products of each 2D matrix A(n,m) that
> >I can extract from the 3D matrix A(n,m,k) with the vector V(m,1).
> >
> > Is it possible to do it in one single command using<sum> ?
> > I mean without the for..end loop.
> >
> > Thanks again
> > P

>
>
> may be:
>
> %data
> clear all
> A=rand(2,2,2);
> b=rand(2,1);
>
> %engine
> ----------------------------
> sum(cell2mat(arrayfun(@(i) A(:,:,i)*b,1:size(A,3),'UniformOutput',false)),2)
> ----------------------------
>
> %verify
> A(:,:,1)*b+A(:,:,2)*b
>
>
> --Nasser

Perfect!
Thanks Nasser

P

Date Subject Author
1/2/12 Paolo Tarpanelli
1/2/12 Nasser Abbasi
1/2/12 Paolo Tarpanelli
1/2/12 James Tursa
1/2/12 Matt J
1/2/12 Matt J
1/2/12 Nasser Abbasi
1/3/12 Matt J

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