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:
sub-matrix extraction

Subject: sub-matrix extraction

From: Abbas Cheddad

Date: 1 May, 2008 17:30:12

Message: 1 of 7

Hi!

I am ruining into a problem of sub-matrix extraction after
merging. The scenario goes as such:

I have four matrices (A,B,C,D) each of which is a 2D MxN
matrix. I created a container matrix consisting of
instances of the aforementioned matrices.

NEW=[A,B;C,D];

I tried to extract back the 4 matrices separately but could
not figure out the right coordinates.

Any help would be much appreciated.

Cheers.
Cheddad

Subject: sub-matrix extraction

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 1 May, 2008 17:51:43

Message: 2 of 7

In article <fvcun4$d2o$1@fred.mathworks.com>,
Abbas Cheddad <cheddad10NOSPAM@yahoo.com> wrote:

>I am ruining into a problem of sub-matrix extraction after
>merging. The scenario goes as such:

>I have four matrices (A,B,C,D) each of which is a 2D MxN
>matrix. I created a container matrix consisting of
>instances of the aforementioned matrices.

>NEW=[A,B;C,D];

>I tried to extract back the 4 matrices separately but could
>not figure out the right coordinates.

nA = NEW(1:N,1:M);
nB = NEW(1:N,M+1:end);
nC = NEW(N+1:end,1:M);
nD = NEW(N+1:end,M+1:end);
--
'Roberson' is my family name; my given name is 'Walter'.

Subject: sub-matrix extraction

From: Abbas Cheddad

Date: 1 May, 2008 18:23:03

Message: 3 of 7

Thank you Walter,

I tried that but the dimensions were not those entered.


>> M

M =

   352

>> N

N =

   640

>> size(nA)

ans =

   640 352

>> size(nB)

ans =

   640 928

>> size(nC)

ans =

    64 352

>> size(nD)

ans =

    64 928

>>


I guess Matlab pads the matrices with some black rows and
columns.

Cheers.
Cheddad
============





roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <fvcvvf$i5p$1@canopus.cc.umanitoba.ca>...
> In article <fvcun4$d2o$1@fred.mathworks.com>,
> Abbas Cheddad <cheddad10NOSPAM@yahoo.com> wrote:
>
> >I am ruining into a problem of sub-matrix extraction
after
> >merging. The scenario goes as such:
>
> >I have four matrices (A,B,C,D) each of which is a 2D MxN
> >matrix. I created a container matrix consisting of
> >instances of the aforementioned matrices.
>
> >NEW=[A,B;C,D];
>
> >I tried to extract back the 4 matrices separately but
could
> >not figure out the right coordinates.
>
> nA = NEW(1:N,1:M);
> nB = NEW(1:N,M+1:end);
> nC = NEW(N+1:end,1:M);
> nD = NEW(N+1:end,M+1:end);
> --
> 'Roberson' is my family name; my given name is 'Walter'.

Subject: sub-matrix extraction

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 1 May, 2008 18:29:23

Message: 4 of 7

In article <fvcvvf$i5p$1@canopus.cc.umanitoba.ca>,
Walter Roberson <roberson@ibd.nrc-cnrc.gc.ca> wrote:

>nA = NEW(1:N,1:M);
>nB = NEW(1:N,M+1:end);
>nC = NEW(N+1:end,1:M);
>nD = NEW(N+1:end,M+1:end);

Sorry, reverse N and M.

nA = NEW(1:M,1:N);
nB = NEW(1:M,N+1:end);
nC = NEW(M+1:end,1:N);
nD = NEW(M+1:end,N+1:end);

--
  "There is no greater calling than to serve your fellow men.
   There is no greater contribution than to help the weak.
   There is no greater satisfaction than to have done it well."
                                              -- Walter Reuther

Subject: sub-matrix extraction

From: Abbas Cheddad

Date: 1 May, 2008 18:39:03

Message: 5 of 7

Thanks Walter for the quick reply, it works now. You have
done it well.

All the best.

Cheddad
================


roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <fvd263$li3$1@canopus.cc.umanitoba.ca>...
> In article <fvcvvf$i5p$1@canopus.cc.umanitoba.ca>,
> Walter Roberson <roberson@ibd.nrc-cnrc.gc.ca> wrote:
>
> >nA = NEW(1:N,1:M);
> >nB = NEW(1:N,M+1:end);
> >nC = NEW(N+1:end,1:M);
> >nD = NEW(N+1:end,M+1:end);
>
> Sorry, reverse N and M.
>
> nA = NEW(1:M,1:N);
> nB = NEW(1:M,N+1:end);
> nC = NEW(M+1:end,1:N);
> nD = NEW(M+1:end,N+1:end);
>
> --
> "There is no greater calling than to serve your fellow
men.
> There is no greater contribution than to help the weak.
> There is no greater satisfaction than to have done it
well."
> -- Walter
Reuther

Subject: sub-matrix extraction

From: Jos

Date: 1 May, 2008 19:47:03

Message: 6 of 7

"Abbas Cheddad" <cheddad10NOSPAM@yahoo.com> wrote in
message <fvd2o7$61b$1@fred.mathworks.com>...
> Thanks Walter for the quick reply, it works now. You have
> done it well.
>
> All the best.
>
> Cheddad
> ================
>
>
> roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
> message <fvd263$li3$1@canopus.cc.umanitoba.ca>...
> > In article <fvcvvf$i5p$1@canopus.cc.umanitoba.ca>,
> > Walter Roberson <roberson@ibd.nrc-cnrc.gc.ca> wrote:
> >
> > >nA = NEW(1:N,1:M);
> > >nB = NEW(1:N,M+1:end);
> > >nC = NEW(N+1:end,1:M);
> > >nD = NEW(N+1:end,M+1:end);
> >
> > Sorry, reverse N and M.
> >
> > nA = NEW(1:M,1:N);
> > nB = NEW(1:M,N+1:end);
> > nC = NEW(M+1:end,1:N);
> > nD = NEW(M+1:end,N+1:end);
> >
> > --
> > "There is no greater calling than to serve your
fellow
> men.
> > There is no greater contribution than to help the
weak.
> > There is no greater satisfaction than to have done
it
> well."
> > -- Walter
> Reuther
>

MAT2CELL could also be helpful in this case.

If X is your 2xN-by-2xM matrix, then

CX = mat2cell(X,[N N],[M M]) ;

will give you a 2-by-2 cell array CX, where each cell
contains a block of the original matrix. This can be
followed by

[a,b,c,d] = deal(CX{:}) ;

to give you the matrices in separated variables, so they
can clutter your workspace ...

Jos

Subject: sub-matrix extraction

From: Abbas Cheddad

Date: 2 May, 2008 08:48:03

Message: 7 of 7

Thanks Jos for the hint.
Cheddad
==========


"Jos " <DELjos@jasenDEL.nl> wrote in message
<fvd6nn$fsc$1@fred.mathworks.com>...
> "Abbas Cheddad" <cheddad10NOSPAM@yahoo.com> wrote in
> message <fvd2o7$61b$1@fred.mathworks.com>...
> > Thanks Walter for the quick reply, it works now. You
have
> > done it well.
> >
> > All the best.
> >
> > Cheddad
> > ================
> >
> >
> > roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
> > message <fvd263$li3$1@canopus.cc.umanitoba.ca>...
> > > In article <fvcvvf$i5p$1@canopus.cc.umanitoba.ca>,
> > > Walter Roberson <roberson@ibd.nrc-cnrc.gc.ca> wrote:
> > >
> > > >nA = NEW(1:N,1:M);
> > > >nB = NEW(1:N,M+1:end);
> > > >nC = NEW(N+1:end,1:M);
> > > >nD = NEW(N+1:end,M+1:end);
> > >
> > > Sorry, reverse N and M.
> > >
> > > nA = NEW(1:M,1:N);
> > > nB = NEW(1:M,N+1:end);
> > > nC = NEW(M+1:end,1:N);
> > > nD = NEW(M+1:end,N+1:end);
> > >
> > > --
> > > "There is no greater calling than to serve your
> fellow
> > men.
> > > There is no greater contribution than to help the
> weak.
> > > There is no greater satisfaction than to have done
> it
> > well."
> > > --
Walter
> > Reuther
> >
>
> MAT2CELL could also be helpful in this case.
>
> If X is your 2xN-by-2xM matrix, then
>
> CX = mat2cell(X,[N N],[M M]) ;
>
> will give you a 2-by-2 cell array CX, where each cell
> contains a block of the original matrix. This can be
> followed by
>
> [a,b,c,d] = deal(CX{:}) ;
>
> to give you the matrices in separated variables, so they
> can clutter your workspace ...
>
> Jos

Tags for 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