Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
multiplication of matrix blocks

Subject: multiplication of matrix blocks

From: audley james

Date: 15 Oct, 2010 00:49:04

Message: 1 of 8

Hello all,

I'm a novice Matlab user asking for a bit of help.

I have 2 matrices:

R = [ 123 32 11 53 69 18 ;
             89 14 2 9 24 45]

S = [ 11 33 ; 20 16 ; 7 3]

I would like to multiply them in blocks as follows without manually typing each multiplication out.

M1 = [ 123 32 ; 89 14] x [ 11 ; 33]
M2 = [ 11 53 ; 2 9] x [ 20 ; 16 ]
M3 = [ 69 18 ; 24 45] x [ 7 ; 3 ]

Cheers,
audley

Subject: multiplication of matrix blocks

From: James Tursa

Date: 15 Oct, 2010 01:27:03

Message: 2 of 8

"audley james" <audleyer@gmail.com> wrote in message <i988e0$6m9$1@fred.mathworks.com>...
> Hello all,
>
> I'm a novice Matlab user asking for a bit of help.
>
> I have 2 matrices:
>
> R = [ 123 32 11 53 69 18 ;
> 89 14 2 9 24 45]
>
> S = [ 11 33 ; 20 16 ; 7 3]
>
> I would like to multiply them in blocks as follows without manually typing each multiplication out.
>
> M1 = [ 123 32 ; 89 14] x [ 11 ; 33]
> M2 = [ 11 53 ; 2 9] x [ 20 ; 16 ]
> M3 = [ 69 18 ; 24 45] x [ 7 ; 3 ]
>
> Cheers,
> audley

mtimesx(reshape(R,2,2,[]),reshape(S.',2,1,[]))

This will give a 3D result. If you want it as a 2D result you can reshape again:

reshape(mtimesx(reshape(R,2,2,[]),reshape(S.',2,1,[])),2,[])

You can find the function mtimesx on the FEX here:

http://www.mathworks.com/matlabcentral/fileexchange/25977-mtimesx-fast-matrix-multiply-with-multi-dimensional-support

James Tursa

Subject: multiplication of matrix blocks

From: audley james

Date: 15 Oct, 2010 02:13:03

Message: 3 of 8

James,

thanks a lot for the help but I'm getting the following error. Can you suggest something?

%%%%%%%%%%%%%%%%%%%%%%%%%
??? Error using ==> mtimesx_build at 446
Unable to compile mtimesx.c

Error in ==> mtimesx at 271
mtimesx_build;

Error in ==> testing_block_multiplication at 10
reshape(mtimesx(reshape(R,2,2,[]),reshape(S.',2,1,[])),2,[])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


thanks
Audley

Subject: multiplication of matrix blocks

From: audley james

Date: 15 Oct, 2010 02:19:03

Message: 4 of 8

Jus to let you know,


when I run mex-setup , I get the following message when I try to choose [y] for Visual studio 2008 Express.


 Error: Could not find the 64-bit compiler. This may indicate that the
         "X64 Compilers and Tools" or the Microsoft Windows Software
         Development Kit (SDK) is not installed. To build 64-bit MEX-files
         Microsoft Visual C++ 2008 Express Edition requires that these two
         packages are installed properly.




Does it mean I need MS Express 2010 which may be 64 bit?

Audley

Subject: multiplication of matrix blocks

From: audley james

Date: 15 Oct, 2010 04:01:07

Message: 5 of 8

Hi,

can anyone assit me in my problem without use of james's mtimes function. My Matlab is just doesnt seem to compile Mex files.

Its urgent .........need some assistance...please

Audley

Subject: multiplication of matrix blocks

From: James Tursa

Date: 15 Oct, 2010 05:58:03

Message: 6 of 8

"audley james" <audleyer@gmail.com> wrote in message <i98jm3$443$1@fred.mathworks.com>...
> Hi,
>
> can anyone assit me in my problem without use of james's mtimes function. My Matlab is just doesnt seem to compile Mex files.
>
> Its urgent .........need some assistance...please
>
> Audley

Did you try the instructions on this page?

http://www.mathworks.com/support/compilers/R2010a/win64.html

James Tursa

Subject: multiplication of matrix blocks

From: Jan Simon

Date: 15 Oct, 2010 11:04:04

Message: 7 of 8

Dear Audley,

> R = [ 123 32 11 53 69 18 ;
> 89 14 2 9 24 45]
> S = [ 11 33 ; 20 16 ; 7 3]
>
> M1 = [ 123 32 ; 89 14] x [ 11 ; 33]
> M2 = [ 11 53 ; 2 9] x [ 20 ; 16 ]
> M3 = [ 69 18 ; 24 45] x [ 7 ; 3 ]

What about some simple FOR loops?
  R2 = reshape(R, 2, 2, 3);
  ST = transpose(S);
  M = zeros(2, 3);
  for i = 1:3
    M(:, i) = R2(:, :, i) * ST(:, i);
  end

Jan

Subject: multiplication of matrix blocks

From: audley james

Date: 15 Oct, 2010 11:43:04

Message: 8 of 8

James, thanks, I got it working. Much Appreciated

Jan, thanks as well for sharing your approach. Much Appreciated

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us