Multiply cell doubles with a matrix

1 Ansicht (letzte 30 Tage)
Mori
Mori am 13 Jul. 2016
Kommentiert: Mori am 13 Jul. 2016
I have a cell array A which has 1*5 cell, each cell has 12*1 doubles.
How multiply those 12*1 doubles with a MATRIX call B with 12*500 ?
Thank you

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 13 Jul. 2016
Bearbeitet: Andrei Bobrov am 13 Jul. 2016
out = bsxfun(@times,permute(cell2mat(A),[1,3,2]),B); % out - 3D double array
or
out = cellfun(@(x)bsxfun(@times,x,B),A,'un',0); % here out - cell array (1 x 5)
  7 Kommentare
Andrei Bobrov
Andrei Bobrov am 13 Jul. 2016
for your data (MatFiles.mat):
A1 = cellfun(@(x)[x{:}]',A,'un',0);
out = bsxfun(@times,permute(cell2mat(A1),[1,3,2]),B); % out - 3D double array
or
out = cellfun(@(x)bsxfun(@times,x,B),A1,'un',0); % here out - cell array (1 x 5)
Mori
Mori am 13 Jul. 2016
ok great, it works. I relay appreciate.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by