Azzera filtri
Azzera filtri

cell array multiplication vectorization

2 visualizzazioni (ultimi 30 giorni)
K.E.
K.E. il 15 Nov 2016
Risposto: the cyclist il 15 Nov 2016
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)?

Risposte (1)

the cyclist
the cyclist il 15 Nov 2016
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);

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by