Borrar filtros
Borrar filtros

Matrix and vector multiplication elementwise

2 visualizaciones (últimos 30 días)
Rica
Rica el 30 de Nov. de 2012
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 comentario
Azzi Abdelmalek
Azzi Abdelmalek el 30 de Nov. de 2012
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

Iniciar sesión para comentar.

Respuesta aceptada

José-Luis
José-Luis el 30 de Nov. de 2012
bsxfun(@times,a,h)

Más respuestas (4)

Muruganandham Subramanian
Muruganandham Subramanian el 30 de Nov. de 2012
Editada: Muruganandham Subramanian el 30 de Nov. de 2012
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 el 30 de Nov. de 2012
a=[1 2 3;2 3 4;4 5 6]
h=[2 2 2];
kron(a,h)

Azzi Abdelmalek
Azzi Abdelmalek el 30 de Nov. de 2012
Editada: Azzi Abdelmalek el 30 de Nov. de 2012
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 el 30 de Nov. de 2012
Editada: Andrei Bobrov el 30 de Nov. de 2012
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),[])';

Categorías

Más información sobre Dimensionality Reduction and Feature Extraction en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by