# matrix multiplication for "3-D" matrices

1 view (last 30 days)

Show older comments

##### 0 Comments

### Accepted Answer

### More Answers (2)

Fabio Freschi
on 6 Sep 2019

Let's start saying that the data structure you are using is not the best one. See https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval

If you really want to keep that structure, maybe the simplest answer is to make the manual multiplication

C = A*B <- matrix form

c11 = a11*b11+a12*b21 <- element form

since you have array, use .* operator

c11 = a11.*b11+a12.*b21

Note that this works only for 2x2 matrices.

For a more general approach, see

##### 4 Comments

Fabio Freschi
on 6 Sep 2019

If you have data stored in cell arrays, you can use arrayfun

% data

N = 10;

A0 = arrayfun(@(i)rand(2,2),1:N,'UniformOutput',false);

B0 = arrayfun(@(i)rand(2,2),1:N,'UniformOutput',false);

% calculation

C = arrayfun(@(k)A0{k}*B0{k},1:N,'UniformOutput',false)

Catalytic
on 6 Sep 2019

If you have the parallel computing toolbox, you can do this on the GPU with

pagefun(@mtimes,A,B)

but this may only provide gains if the pages A(:,:,i) and B(:,:,i) are large matrices.

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!