Thread Subject: divide and conquer matrix

Subject: divide and conquer matrix

From: Diego Lass

Date: 18 Jun, 2009 20:46:02

Message: 1 of 3

Hi
I have a problem with a large matrix, what I want to do is to divide the matrix into 4 submatrices, do some operation then reassemble the submatrix together. A toy example

A = [1 2 3 ; 3 4 5 ; 2 3 4; 5 1 2 ]
A =

     1 2 3
     3 4 5
     2 3 4
     5 1 2
 I want to divide A into ANY approximately equal sized partitions, for example
1 2
3 4

3
5

2 3
5 1

4
2

then do some operation, say add 2 to each element. Then reassemble them together, to get

     3 4 5
     5 6 7
     4 5 6
     7 3 4
What is the most efficient way of doing this?
Thanks
Diego

Subject: divide and conquer matrix

From: Nicolaie Popescu-Bodorin

Date: 19 Jun, 2009 00:59:02

Message: 2 of 3

-use powers of two as much as possible;
-see blkproc (caution with implicit padding);
-if the matrix is huge, consider mex using;
-column is the "fast dimension"; this could be helpful;

Bodorin

"Diego Lass" <dlISCool@gmail.com> wrote in message <h1e92a$bd7$1@fred.mathworks.com>...
> Hi
> I have a problem with a large matrix, what I want to do is to divide the matrix into 4 submatrices, do some operation then reassemble the submatrix together. A toy example
>
> A = [1 2 3 ; 3 4 5 ; 2 3 4; 5 1 2 ]
> A =
>
> 1 2 3
> 3 4 5
> 2 3 4
> 5 1 2
> I want to divide A into ANY approximately equal sized partitions, for example
> 1 2
> 3 4
>
> 3
> 5
>
> 2 3
> 5 1
>
> 4
> 2
>
> then do some operation, say add 2 to each element. Then reassemble them together, to get
>
> 3 4 5
> 5 6 7
> 4 5 6
> 7 3 4
> What is the most efficient way of doing this?
> Thanks
> Diego

Subject: divide and conquer matrix

From: Jos

Date: 19 Jun, 2009 09:40:18

Message: 3 of 3

"Diego Lass" <dlISCool@gmail.com> wrote in message <h1e92a$bd7$1@fred.mathworks.com>...
> Hi
> I have a problem with a large matrix, what I want to do is to divide the matrix into 4 submatrices, do some operation then reassemble the submatrix together. A toy example
>
> A = [1 2 3 ; 3 4 5 ; 2 3 4; 5 1 2 ]
> A =
>
> 1 2 3
> 3 4 5
> 2 3 4
> 5 1 2
> I want to divide A into ANY approximately equal sized partitions, for example
> 1 2
> 3 4
>
> 3
> 5
>
> 2 3
> 5 1
>
> 4
> 2
>
> then do some operation, say add 2 to each element. Then reassemble them together, to get
>
> 3 4 5
> 5 6 7
> 4 5 6
> 7 3 4
> What is the most efficient way of doing this?
> Thanks
> Diego

The definition of "efficient" is open to many interpretations ... Here is an example that is not particularly fast, but quite flexible:

% your data
  A = [1 2 3 ; 3 4 5 ; 2 3 4; 5 1 2 ]
  myfun = @(X) 1110 * X(1) + X ;

% engine
  C = mat2cell(A,[2 2],[2 1]) ;
  C = cellfun(myfun, C,'uniformoutput',false) ;
  B = cell2mat(C)

hth
Jos

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
blkproc Nicolaie Popescu-Bodorin 18 Jun, 2009 21:04:03
matrix operation Diego Lass 18 Jun, 2009 16:49:04
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com