1
votes

I have a cell array size 1x200x201, in each cell is 2x2 matrix. I need to multiply the matrices in a way that I would get resulting matrix: 2x2x201. Which means: Cell_M{1,1,1}* Cell_M{1,2,1}*Cell_M{1,3,1}*... and so on up to 200, and the same up to 201 ( Cell_M{1,1,2}* Cell_M{1,2,2}*Cell_M{1,3,2}*... ). Cell arrays is just a way for handling the data. Is any effective way to do this multiplications?

1
don't you mean you want a resulting matrix with a size of size 2x200x201?Lucius II.
Can you make a mock up using for loops for a much smaller data set, say 1x2x3 ?Dan
200 - are different layers from measured sample, and 201 are different angles, in the end I need to have the values for all the angles.Essential_M
The resulting matrix should be 2x2x201 for every angle: multiply all 200 matrices (in layers) together. The number of angles and layers can change in general code. That's quite problematic because I need to make all that many matrices multiplicationEssential_M

1 Answers

1
votes

Floating-point matrix multiplication is not associative in general, so A*B*C*D is ambiguous. In this code I assume you are looking for ((A*B)*C)*D

d=size(Cell_M); 
P = cell(d(1), 1, d(3)); 
P(:)={eye(2)}; 
for k=1:d(2), 
    P = cellfun(@mtimes, P(:,1,:), Cell_M(:,k,:), 'UniformOutput', false); 
end
P = squeeze(P);

Now P will be a cell array of 201 elements where each element is a 2-by-2 matrix.