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:
split matrix into small matricess

Subject: split matrix into small matricess

From: Faisal

Date: 2 Dec, 2010 17:59:05

Message: 1 of 6

I have a matrix (300 x 25)

i want to divide it into 10 matrice such that
a) each matrix has 30 rows
b) each matrix has 25 columns

i.e. number of columns are same always
answer should be like

M1 = 30 x 25 (rows start from 1 and end at 30)
M2 = 30 x 25 (rows start from 31 and ends at 60)
M3 = 30 x 25 (rows start from 61 and ends at 90)
.
.
.
how i can solve this problem?

Subject: split matrix into small matricess

From: Sean de

Date: 2 Dec, 2010 18:10:24

Message: 2 of 6

"Faisal " <artistlikeu@yahoo.com> wrote in message <id8mp9$fgv$1@fred.mathworks.com>...
> I have a matrix (300 x 25)
>
> i want to divide it into 10 matrice such that
> a) each matrix has 30 rows
> b) each matrix has 25 columns
>
> i.e. number of columns are same always
> answer should be like
>
> M1 = 30 x 25 (rows start from 1 and end at 30)
> M2 = 30 x 25 (rows start from 31 and ends at 60)
> M3 = 30 x 25 (rows start from 61 and ends at 90)
> .
> .
> .
> how i can solve this problem?

Don't do this!
http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F

A = your_matrix
Mcell = mat2cell(A,repmat(30,10,1),25)

Subject: split matrix into small matricess

From: Walter Roberson

Date: 2 Dec, 2010 18:05:07

Message: 3 of 6

On 02/12/10 11:59 AM, Faisal wrote:
> I have a matrix (300 x 25)
>
> i want to divide it into 10 matrice such that
> a) each matrix has 30 rows
> b) each matrix has 25 columns
>
> i.e. number of columns are same always
> answer should be like
>
> M1 = 30 x 25 (rows start from 1 and end at 30)
> M2 = 30 x 25 (rows start from 31 and ends at 60)
> M3 = 30 x 25 (rows start from 61 and ends at 90)
> .
> .
> .
> how i can solve this problem?

See mat2cell() for the splitting; it is easy.

The assigning to individually named variables "is left as an exercise to
the reader" (in other words, Don't Do That!)

Subject: split matrix into small matricess

From: James Tursa

Date: 2 Dec, 2010 18:15:56

Message: 4 of 6

"Faisal " <artistlikeu@yahoo.com> wrote in message <id8mp9$fgv$1@fred.mathworks.com>...
> I have a matrix (300 x 25)
>
> i want to divide it into 10 matrice such that
> a) each matrix has 30 rows
> b) each matrix has 25 columns
>
> i.e. number of columns are same always
> answer should be like
>
> M1 = 30 x 25 (rows start from 1 and end at 30)
> M2 = 30 x 25 (rows start from 31 and ends at 60)
> M3 = 30 x 25 (rows start from 61 and ends at 90)
> .
> .
> .
> how i can solve this problem?

A = your 300x25 matrix
X = mat2cell(A,30*ones(10,1),25);

X{1} is your M1, X{2} is your M2, etc.

James Tursa

Subject: split matrix into small matricess

From: Wayne King

Date: 2 Dec, 2010 18:17:08

Message: 5 of 6

"Faisal " <artistlikeu@yahoo.com> wrote in message <id8mp9$fgv$1@fred.mathworks.com>...
> I have a matrix (300 x 25)
>
> i want to divide it into 10 matrice such that
> a) each matrix has 30 rows
> b) each matrix has 25 columns
>
> i.e. number of columns are same always
> answer should be like
>
> M1 = 30 x 25 (rows start from 1 and end at 30)
> M2 = 30 x 25 (rows start from 31 and ends at 60)
> M3 = 30 x 25 (rows start from 61 and ends at 90)
> .
> .
> .
> how i can solve this problem?

Hi Faisal, You should spend some time reading the MATLAB Getting Started Guide. The section on Matrices and Arrays explains these basic operations.

M = randn(300,25);
M1 = M(1:30,:);

Wayne

Subject: split matrix into small matricess

From: Faisal

Date: 3 Dec, 2010 10:49:06

Message: 6 of 6

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <id8neg$t3b$1@fred.mathworks.com>...
> "Faisal " <artistlikeu@yahoo.com> wrote in message <id8mp9$fgv$1@fred.mathworks.com>...
> > I have a matrix (300 x 25)
> >
> > i want to divide it into 10 matrice such that
> > a) each matrix has 30 rows
> > b) each matrix has 25 columns
> >
> > i.e. number of columns are same always
> > answer should be like
> >
> > M1 = 30 x 25 (rows start from 1 and end at 30)
> > M2 = 30 x 25 (rows start from 31 and ends at 60)
> > M3 = 30 x 25 (rows start from 61 and ends at 90)
> > .
> > .
> > .
> > how i can solve this problem?
>
> Don't do this!
> http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
>
> A = your_matrix
> Mcell = mat2cell(A,repmat(30,10,1),25)

Dear Sean
thnx a lot. It worked.

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