Thread Subject: Divide, operate and reassemble matrix

Subject: Divide, operate and reassemble matrix

From: Diego Lass

Date: 18 Jun, 2009 21:23:01

Message: 1 of 5

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 4 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, operate and reassemble matrix

From: Nathan

Date: 18 Jun, 2009 21:30:10

Message: 2 of 5

On Jun 18, 2:23 pm, "Diego Lass" <dlISC...@gmail.com> wrote:
> 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 4 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

You just posted this not an hour ago with a different title... Why?

Why disassemble and do operations when you can just do that operation
to each element in one instruction?

Subject: Divide, operate and reassemble matrix

From: Diego Lass

Date: 18 Jun, 2009 21:41:01

Message: 3 of 5

Oh, because when I run whatever I wrote, I got the following error

??? Error using ==> minus
Maximum variable size allowed by the program is exceeded.

Error in ==> [some program] at 18
   [equation involves matrix .*, ./ and (1 - some matrix .^)]

However, when I tested on a smaller matrix, the code works
So I was thinking maybe if I divide the matrix into submatrices, do the thing and reassemble them, the code might work.

Thanks
Diego

Nathan <ngreco32@gmail.com> wrote in message <728fb21e-1182-4780-b27d-44a4d369d85f@o21g2000prn.googlegroups.com>...
> On Jun 18, 2:23?pm, "Diego Lass" <dlISC...@gmail.com> wrote:
> > 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 4 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
>
> You just posted this not an hour ago with a different title... Why?
>
> Why disassemble and do operations when you can just do that operation
> to each element in one instruction?

Subject: Divide, operate and reassemble matrix

From: Nathan

Date: 18 Jun, 2009 21:54:43

Message: 4 of 5

On Jun 18, 2:41 pm, "Diego Lass" <dlISC...@gmail.com> wrote:
> Oh, because when I run whatever I wrote, I got the following error
>
> ??? Error using ==> minus
> Maximum variable size allowed by the program is exceeded.
>
> Error in ==> [some program] at 18
>    [equation involves matrix .*, ./ and (1 - some matrix .^)]
>
> However, when I tested on a smaller matrix, the code works
> So I was thinking maybe if I divide the matrix into submatrices, do the thing and reassemble them, the code might work.
>
> Thanks
> Diego  
>
> Nathan <ngrec...@gmail.com> wrote in message <728fb21e-1182-4780-b27d-44a4d369d...@o21g2000prn.googlegroups.com>...
> > On Jun 18, 2:23?pm, "Diego Lass" <dlISC...@gmail.com> wrote:
> > > 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 4 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
>
> > You just posted this not an hour ago with a different title... Why?
>
> > Why disassemble and do operations when you can just do that operation
> > to each element in one instruction?

Are you using bsxfun?
If not, check that out. It might be what you're looking for.

Subject: Divide, operate and reassemble matrix

From: Diego Lass

Date: 18 Jun, 2009 22:03:01

Message: 5 of 5

Well, I want to calculate the t-stat of a correlation matrix, i.e.

Tstat = correlation .* sqrt((nv-2) ./ (1 - correlation.^2));

nv is the degree of freedom. I am not sure how to do that with bsxfun.

Diego


Nathan <ngreco32@gmail.com> wrote in message <092599c9-0913-410c-8f88-cc3911772334@x31g2000prc.googlegroups.com>...
> On Jun 18, 2:41?pm, "Diego Lass" <dlISC...@gmail.com> wrote:
> > Oh, because when I run whatever I wrote, I got the following error
> >
> > ??? Error using ==> minus
> > Maximum variable size allowed by the program is exceeded.
> >
> > Error in ==> [some program] at 18
> > ? ?[equation involves matrix .*, ./ and (1 - some matrix .^)]
> >
> > However, when I tested on a smaller matrix, the code works
> > So I was thinking maybe if I divide the matrix into submatrices, do the thing and reassemble them, the code might work.
> >
> > Thanks
> > Diego ?
> >
> > Nathan <ngrec...@gmail.com> wrote in message <728fb21e-1182-4780-b27d-44a4d369d...@o21g2000prn.googlegroups.com>...
> > > On Jun 18, 2:23?pm, "Diego Lass" <dlISC...@gmail.com> wrote:
> > > > 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 4 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
> >
> > > You just posted this not an hour ago with a different title... Why?
> >
> > > Why disassemble and do operations when you can just do that operation
> > > to each element in one instruction?
>
> Are you using bsxfun?
> If not, check that out. It might be what you're looking for.

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
matrix operation Diego Lass 18 Jun, 2009 17:24: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