필터 지우기
필터 지우기

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),[])';

카테고리

Help CenterFile Exchange에서 Dimensionality 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