Prev: z-transform,step function
Next: mat lab
From: Vihar on 8 Dec 2009 14:22 Hello, I've been trying to perform a 3D matrix multiplication and have not been successful. My two matrices are of size m x n x p and I want to be able to carry out A*B in 3 dimensions. I've spent a few hours on the boards here searching for some help but have failed to find anything, so your help will be greatly appreciated. Thanks
From: dpb on 8 Dec 2009 14:34 Vihar wrote: > Hello, > > I've been trying to perform a 3D matrix multiplication and have not > been successful. My two matrices are of size m x n x p and I want to > be able to carry out A*B in 3 dimensions. I've spent a few hours on > the boards here searching for some help but have failed to find > anything, so your help will be greatly appreciated. You don't say what your definition of the result should be -- one surmise would be -- >> >> a=rand(2,3,2); % get some data to play with >> b=rand(3,2,2); >> c=zeros(size(a,1),size(b,2),size(a,3); % preallocate result >> for i=1:size(a,3),c(:,:,i)=a(:,:,i)*b(:,:,i);end --
From: James Tursa on 8 Dec 2009 15:54 dpb <none(a)non.net> wrote in message <hfm9p3$mbh$1(a)news.eternal-september.org>... > Vihar wrote: > > Hello, > > > > I've been trying to perform a 3D matrix multiplication and have not > > been successful. My two matrices are of size m x n x p and I want to > > be able to carry out A*B in 3 dimensions. I've spent a few hours on > > the boards here searching for some help but have failed to find > > anything, so your help will be greatly appreciated. > > You don't say what your definition of the result should be -- one > surmise would be -- > > >> > >> a=rand(2,3,2); % get some data to play with > >> b=rand(3,2,2); > >> c=zeros(size(a,1),size(b,2),size(a,3); % preallocate result > >> for i=1:size(a,3),c(:,:,i)=a(:,:,i)*b(:,:,i);end For this result you can use my MTIMESX submission in the FEX: http://www.mathworks.com/matlabcentral/fileexchange/25977-mtimesx-fast-matrix-multiply-with-multi-dimensional-support a=rand(2,3,2); % get some data to play with b=rand(3,2,2); c=mtimesx(a,b); % fast result w/o loops MTIMESX is a fast BLAS based nD matrix multiply routine. James Tursa
|
Pages: 1 Prev: z-transform,step function Next: mat lab |