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:
How to Split a Matrix

Subject: How to Split a Matrix

From: Nehal

Date: 5 Aug, 2010 19:22:04

Message: 1 of 4

I have a matrix like...

A = [ 1 2 3 4 5 6 7 8 9
        1 2 3 4 5 6 7 8 9
        1 2 3 4 5 6 7 8 9
        1 2 3 4 5 6 7 8 9
        1 2 3 4 5 6 7 8 9]

I want to split it like...

B = [1 2 5 6 9
       1 2 5 6 9
       1 2 5 6 9
       1 2 5 6 9
       1 2 5 6 9]

C = [3 4 7 8
       3 4 7 8
       3 4 7 8
       3 4 7 8
       3 4 7 8]

In my case, I have a huge matrix.. so I want it to be done in a little automatic way...

Like I want to come up with a code that will split a matrix (A) into 2 individual matrix. Where, the 1st matrix (B) will contain all the 1st, 2nd, 5th, 6th, 9th columns. And the 2nd matrix (C) will contain all the 3rd, 4th, 7th, 8th columns of matrix (A).

Can anyone help me..? plz..

Subject: How to Split a Matrix

From: Matt Fig

Date: 5 Aug, 2010 19:28:05

Message: 2 of 4

B = A(:,[1 2 5 6 9])
C = A(:[3 4 7 8])

Also, I recommend taking the time to read the "Getting Started" section of the help.

Subject: How to Split a Matrix

From: Walter Roberson

Date: 5 Aug, 2010 19:31:05

Message: 3 of 4

Nehal wrote:

> Like I want to come up with a code that will split a matrix (A) into 2
> individual matrix. Where, the 1st matrix (B) will contain all the 1st,
> 2nd, 5th, 6th, 9th columns. And the 2nd matrix (C) will contain all the
> 3rd, 4th, 7th, 8th columns of matrix (A).

B = A(:,[1 2 5 6 9]);
C = A(:,[3 4 7 8]);

Subject: How to Split a Matrix

From: Nehal

Date: 5 Aug, 2010 19:39:19

Message: 4 of 4

"Matt Fig" <spamanon@yahoo.com> wrote in message <i3f3c5$qtd$1@fred.mathworks.com>...
> B = A(:,[1 2 5 6 9])
> C = A(:[3 4 7 8])
>
> Also, I recommend taking the time to read the "Getting Started" section of the help.

Thank You.
And yes, I'll do that too.. :)

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