From: Frank on
I have a 2 by 42 matrix and another 2 by 42 matrix like the following:

A = [ 1 135 687 974 784... ;7694 4153 7894 951...]
B= [ 68 15 789 7984...; 4687 4175 9541 358...]

I would like to do a matrix multiplication of each 2x2 matrix contained in A by each 2x2 matrix in B, like the following:

For the first 2x2 matrix set
[1 135 ; 7694 4153] * [68 15 ; 4687 4175]

which equals [632813 563640 ; 19988303 17454185]

For the second 2x2 matrix set
[974 784; 7894 951] * [789 7984 ; 9541 358]

which equals [8248630 8057088 ; 15301857 63366154]

and so on.

The final results from each of those 2x2 matrix multiplications should be stored in another 2 by 42 matrix like the following

C = [632813 563640 8248630 8057088 ; 19988303 17454185 15301857 63366154]

I'd perfer not use for loops to minimize process time unless there is no other way around it.

Thanks very much.
From: Matt J on
"Frank " <ecmatlab(a)gmail.com> wrote in message <i1if76$jjk$1(a)fred.mathworks.com>...

> I'd perfer not use for loops to minimize process time unless there is no other way around it.
=========

I doubt a for-loop of only 21 passes, and for such a trivial calculation, can be improved upon by much.
From: Bruno Luong on
"Frank " <ecmatlab(a)gmail.com> wrote in message <i1if76$jjk$1(a)fred.mathworks.com>...
> I have a 2 by 42 matrix and another 2 by 42 matrix like the following:
>
> A = [ 1 135 687 974 784... ;7694 4153 7894 951...]
> B= [ 68 15 789 7984...; 4687 4175 9541 358...]
>
> I would like to do a matrix multiplication of each 2x2 matrix contained in A by each 2x2 matrix in B, like the following:
>
> For the first 2x2 matrix set
> [1 135 ; 7694 4153] * [68 15 ; 4687 4175]
>
> which equals [632813 563640 ; 19988303 17454185]
>
> For the second 2x2 matrix set
> [974 784; 7894 951] * [789 7984 ; 9541 358]
>
> which equals [8248630 8057088 ; 15301857 63366154]
>
> and so on.
>
> The final results from each of those 2x2 matrix multiplications should be stored in another 2 by 42 matrix like the following
>
> C = [632813 563640 8248630 8057088 ; 19988303 17454185 15301857 63366154]
>
> I'd perfer not use for loops to minimize process time unless there is no other way around it.
>
> Thanks very much.

You can reshape your 2d arrays in 3d arrays (2x2xn), then call one of the function in FEX, e..g,:

http://www.mathworks.com/matlabcentral/fileexchange/25977

http://www.mathworks.com/matlabcentral/fileexchange/24260

Bruno
From: Frank on
"Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <i1ihq5$bas$1(a)fred.mathworks.com>...
> "Frank " <ecmatlab(a)gmail.com> wrote in message <i1if76$jjk$1(a)fred.mathworks.com>...
>
> > I'd perfer not use for loops to minimize process time unless there is no other way around it.
> =========
>
> I doubt a for-loop of only 21 passes, and for such a trivial calculation, can be improved upon by much.

This will be expanded to a matrix with at least 1000-2000 2x2 matrices rather than 21, so a for loop may take some time, but thanks for your input.
From: Frank on
> You can reshape your 2d arrays in 3d arrays (2x2xn), then call one of the function in FEX, e..g,:
>
> http://www.mathworks.com/matlabcentral/fileexchange/25977
>
> http://www.mathworks.com/matlabcentral/fileexchange/24260
>
> Bruno

I'll take a look at the functions you suggested. Thanks for the 3D array idea and input.