Да, вы можете, используя третье измерение, сохранить промежуточные результаты и преобразовать их обратно в 2D. Таким образом, вы также можете избежать самого kron
, который не самый быстрый.
Matlab R2016a или более поздней версии:
a = C(J,:).' .* permute(B(:,I),[3 2 1]); %// calculation of the product to 3rd dimension
%// by implicit expansion
b = permute(a, [3 1 2]); %// permuting
out = reshape(b, [], 3) %// reshape to desired form
коротко:
out = reshape(permute(C(J,:).' .* permute(B(:,I),[3 2 1]), [3 1 2]), [], 3)
Перед Matlab R2016a:
a = bsxfun(@times , C(J,:).', permute(B(:,I),[3 2 1])); %// calculation of
%// the product to 3rd dimension(explicit)
b = permute(a, [3 1 2]); %// permuting
out = reshape(b, [], 3) %// reshape to desired form
коротко:
out = reshape(permute(bsxfun(@times , C(J,:).', permute(B(:,I),[3 2 1])), [3 1 2]), [], 3)