How can I multiply cell arrays

5 次查看(过去 30 天)
Hi everyone,
I have a cell array A 2x100. Each element of A is a 6x1 matrix. If B is a 101x6 matrix. I want to multiply each raw of the last 100 raws of B with every element of A. Thus at the end it should deliver a 2x100 cell array of scalars. I 've tried
for k=1:2;
for i=1:100;
C=num2cell(cell2mat(A(k,:)).*cell2mat(B{k,2:end}(:,1)));
end;
end;
Unfortunately it doesn't work. Thanks in advance.

采纳的回答

michio
michio 2016-11-19
编辑:michio 2016-11-19
Not sure if the way you described is the best way to proceed but here you can make use of cellfun to achieve I think what you described.
A = rand(12,100);
Ac = mat2cell(A,[6,6],ones(1,100));
B = rand(101,6);
Bc = mat2cell(B(2:end,:),ones(100,1),6);
Created sample data. Ac is a 2x100 cell array with 6x1 vector in each cell. Bc is a 100x1 cell array with 1x6 vector in each cell. Now cellfun to multiply vectors in each cells
BcAc1 = cellfun(@mtimes,Bc',Ac(1,:), 'UniformOutput', false);
BcAc2 = cellfun(@mtimes,Bc',Ac(2,:), 'UniformOutput', false);
% Concatinate the results to create 2x100 cell array with a scalar in each cell
BcAc = [BcAc1; BcAc2];
whos BcAc

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matched Filter and Ambiguity Function 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by