MATLAB: How to multiply a vector 3 times to get a 3 dimentional matrix

Hi,
Suppose I have a vector B = [1 2 3]. Then
B*B' = [1*1 1*2 1*3 ; 2*1 2*2 2*3 ; 3*1 3*2 3*3]
Now, I need to multiply the new matrix B*B' again with B, in order to get the following 3 dimentional matrix C:
C(:,:,1) = [1*1*1 1*2*1 1*3*1 ; 2*1*1 2*2*1 2*3*1 ; 3*1*1 3*2*1 3*3*1]
C(:,:,2) = [1*1*2 1*2*2 1*3*2 ; 2*1*2 2*2*2 2*3*2 ; 3*1*2 3*2*2 3*3*2]
C(:,:,3) = [1*1*3 1*2*3 1*3*3 ; 2*1*3 2*2*3 2*3*3 ; 3*1*3 3*2*3 3*3*3]
Any ideas how can I do that?
(My original vector is long so I can not do this manually..)
Thanks!

Best Answer

B * B' .* reshape( B, [1 1 3] );
if B starts as a column matrix. In your case above B * B' would in itself result in a scalar as B is a row matrix.
Obviously if you start with a row vector you can just do
B' * B .* reshape( B, [1 1 3] )