Question #5930

Hi,

I am working on my project on matlab where I have to divide an array of size 1X711000 in to subarrays of size of 1X100.

Can I use the command mat2cell command for it?

Please give the proper command for it.

I am working on my project on matlab where I have to divide an array of size 1X711000 in to subarrays of size of 1X100.

Can I use the command mat2cell command for it?

Please give the proper command for it.

Expert's answer

Suppose your array is called A and has size 1 x N*M, so it is a row.

To

divide it into N cell arrays of length M use the command:

C =

mat2cell(A,[1],ones(1,N)*M);

Now to access the i-th M-tuple you should

run

C{i}

In your case you should run

C =

mat2cell(A,[1],ones(1,7110)*100);

===============================

Another

approach is to convert A into M x N array (M rows and N columns) by the

command

D = reshape(A,M,N)

Then to access the i-th M-tuple

run

D(:,i)

In your case use the command

D =

reshape(A,100,7110)

To

divide it into N cell arrays of length M use the command:

C =

mat2cell(A,[1],ones(1,N)*M);

Now to access the i-th M-tuple you should

run

C{i}

In your case you should run

C =

mat2cell(A,[1],ones(1,7110)*100);

===============================

Another

approach is to convert A into M x N array (M rows and N columns) by the

command

D = reshape(A,M,N)

Then to access the i-th M-tuple

run

D(:,i)

In your case use the command

D =

reshape(A,100,7110)

Learn more about our help with Assignments: ProgrammingMatlab

## Comments

## Leave a comment