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

1 Ansicht (letzte 30 Tage)
JazzMusic
JazzMusic am 28 Nov. 2016
Kommentiert: JazzMusic am 28 Nov. 2016
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!

Akzeptierte Antwort

Adam
Adam am 28 Nov. 2016
Bearbeitet: Adam am 28 Nov. 2016
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] )

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by