cell array multiplication vectorization

1 次查看(过去 30 天)
I have J and K a cell array of matrices inside. I want to obtain L
J =
[18x18 double]
[18x18 double]
[18x18 double]
[18x18 double]
[18x18 double]
[18x18 double]
[18x18 double]
[18x18 double]
K =
[18x18 double]
[18x18 double]
[18x18 double]
[18x18 double]
[18x18 double]
[18x18 double]
[18x18 double]
[18x18 double]
M = magic(18);
In for loop:
L = cell(8,1);
for ii = 1:8
L{ii} = M*J{ii}'*K{ii};
end
How can I do this in a vectorized form (cell)?

回答(1 个)

the cyclist
the cyclist 2016-11-15
This is a bit obfuscated, and I am not sure if it is an faster than a more straightforward version.
% Create some pretend data to mimic yours
M = magic(18);
for ii = 1:8
J{ii} = rand(18);
K{ii} = rand(18);
end
% Vectorized multiplication
C = cellfun(@(a,b,c)(a*b'*c),repmat({M},1,8),J,K,'UniformOutput',false);

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by