フィルターのクリア

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

1 回表示 (過去 30 日間)
JazzMusic
JazzMusic 2016 年 11 月 28 日
コメント済み: JazzMusic 2016 年 11 月 28 日
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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by