Matrix and vector multiplication elementwise

2 ビュー (過去 30 日間)
Rica
Rica 2012 年 11 月 30 日
I have a big matrix and vector. itry to present my problem with this exemple:
%
a=[1 2 3;2 3 4;4 5 6]
h=[2 2 2]
how to calculate:
%
C=[a(1,1)*h(1) a(1,1)*h(2) a(1,1)*h(3); a(2,1)*h(1) a(2,1)*h(2) a(2,2);.......;...;a(3,3)*h(1) a(3,3)*h(2) a(3,3)*h(3)]:
?
Thank you
  1 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 11 月 30 日
The answer you've accepted don't answer your question, the size of your matrix
C=[a(1,1)*h(1) a(1,1)*h(2) a(1,1)*h(3); a(2,1)*h(1) a(2,1)*h(2) a(2,2);.......;...;a(3,3)*h(1) a(3,3)*h(2) a(3,3)*h(3)]:
is 9x3 while José-Luis result is 3x3

サインインしてコメントする。

採用された回答

José-Luis
José-Luis 2012 年 11 月 30 日
bsxfun(@times,a,h)

その他の回答 (4 件)

Muruganandham Subramanian
Muruganandham Subramanian 2012 年 11 月 30 日
編集済み: Muruganandham Subramanian 2012 年 11 月 30 日
hi,
a=[1 2 3;2 3 4;4 5 6];
h=[2 2 2];
for i=1:3
for j=1:3
c(i,j)=a(i,j)*h(i);
end
end
disp(c)

Wayne King
Wayne King 2012 年 11 月 30 日
a=[1 2 3;2 3 4;4 5 6]
h=[2 2 2];
kron(a,h)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 11 月 30 日
編集済み: Azzi Abdelmalek 2012 年 11 月 30 日
a=[1 2 3;2 3 4;4 5 6]
h=[2 2 2]
out=cell2amt(arrayfun(@(x) x*h,a(:),'uni',0))

Andrei Bobrov
Andrei Bobrov 2012 年 11 月 30 日
編集済み: Andrei Bobrov 2012 年 11 月 30 日
Rica wrote: "...how to calculate: ...
C=[a(1,1)*h(1) a(1,1)*h(2) a(1,1)*h(3); a(2,1)*h(1) a(2,1)*h(2) a(2,2);.......;...;a(3,3)*h(1) a(3,3)*h(2) a(3,3)*h(3)]: ..."
out = reshape(bsxfun(@times,reshape(a,1,size(a,1),[]),h(:)),numel(h),[])';
  1 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 11 月 30 日
Yes, we 've got the same result

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDimensionality Reduction and Feature Extraction についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by