Multiplying matrices of different sizes

Is there a compact way to multiply matrices of different sizes?
I would like to multiply the elements of a 4D 10x29x34x28 matrix by the elements in a 10x1 matrix (i.e. the multiplier only differs over the first dimension).
At the moment I have just constructed a 4D matrix out of the 10x1 matrix, but that's a little slow. I am hoping that there is a more graceful solution.

1 comentario

Image Analyst
Image Analyst el 1 de Jun. de 2015
That's only 276080 elements - it should be faster than a greased cheetah on steroids. How long is it taking? What is your current method?

Iniciar sesión para comentar.

 Respuesta aceptada

Stephen23
Stephen23 el 1 de Jun. de 2015
Editada: Stephen23 el 1 de Jun. de 2015
It seems that you are looking for element-wise multiplication, with singleton dimension expansion... which is what bsxfun is for:
>> A = rand(10,29,34,28);
>> B = (1:10)';
>> C = bsxfun(@times,A,B);
>> size(C)
ans =
10 29 34 28

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Preguntada:

el 1 de Jun. de 2015

Comentada:

el 1 de Jun. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by