How to make a 3D matrix from 3 vectors?

12 vues (au cours des 30 derniers jours)
John
John le 13 Jan 2016
Commenté : John le 13 Jan 2016
3 vectors, a b c, to be used as factor or filter for a 3D matrix V. For 2D it's easy and elegant:
d=a'*b;
f=M.*d; % M 2D matrix
The 3D filter can be done this way:
f=V*0.0;
for n=1:n3
f(:,:,n)=V(:,:,n)*c(n);
end
Is there a more elegant way for this? For example make a 3D matrix D from the 3 vector and then
f=D.*V
Thanks

Réponse acceptée

Matt J
Matt J le 13 Jan 2016
Modifié(e) : Matt J le 13 Jan 2016
For filtering, it is probably not a good idea to convolve with d or D. Instead, you should filter separably. For example, in 2D, you could do,
f = conv2(a,b,M);
For element-wise multiplication in 3D, I similarly don't think building D is the way to go, as it creates an unnecessary extra array. I would probably do,
f=bsxfun(@times,V, a(:)*b(:).');
f=bsxfun(@times,f, reshape(c,1,1,[]));
But, if you really insist on building D, you could do
D = bsxfun(@times, a(:)*b(:).', reshape(c,1,1,[]));
Or, you could do
d=a(:)*b(:).';
D=reshape(d(:)*c(:).', size(V));
  1 commentaire
John
John le 13 Jan 2016
Thanks. That opens a few windows.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

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

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by