Effacer les filtres
Effacer les filtres

Multiply a set of matrices (3D array) by a vector of values

1 vue (au cours des 30 derniers jours)
SuperNano
SuperNano le 7 Juil 2016
Commenté : SuperNano le 7 Juil 2016
I have a 3D array (a) such that size(a) = [n,n,m]. I also have a vector (v) of length(v) = m. I would like to multiply each element from my vector with each 2D matrix in my array. Is there a way to do this without a for loop. To clarify, using a for loop it would be:
for i = 1:m
b(:,:,i) = v(i)*a(:,:,i);
end

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 7 Juil 2016
Modifié(e) : Azzi Abdelmalek le 7 Juil 2016
% -------Example-----------------
M=randi(3,3,2,4)
v=1:4
%--------------------------------
bsxfun(@times,M,reshape(v,1,1,4))
  1 commentaire
SuperNano
SuperNano le 7 Juil 2016
WOW that was fast and effective... thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by