From d156ba5dedf29ee5c9842969375caea1555b36e5 Mon Sep 17 00:00:00 2001 From: Sylvain Calinon Date: Mon, 3 Jul 2017 16:37:36 +0200 Subject: [PATCH] outerprod.m added --- m_fcts/outerprod.m | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 m_fcts/outerprod.m diff --git a/m_fcts/outerprod.m b/m_fcts/outerprod.m new file mode 100644 index 0000000..806037f --- /dev/null +++ b/m_fcts/outerprod.m @@ -0,0 +1,16 @@ +function T = outerprod(U,V,varargin) +% Computation of the outer product between two tensors. + +T = bsxfun(@times,U(:),V(:).'); +totalSize = [size(U) size(V)]; + +for i = 1:numel(varargin) + T = bsxfun(@times,T(:),varargin{i}(:).'); + totalSize = [totalSize, size(varargin{i})]; +end + +totalSize(totalSize==1) = []; + +T = reshape(T, totalSize); + +end \ No newline at end of file -- 2.21.0