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

1 次查看(过去 30 天)
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!

采纳的回答

Adam
Adam 2016-11-28
编辑:Adam 2016-11-28
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] )

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by