Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: how to split a matrix
Replies: 2   Last Post: Mar 16, 2013 9:34 AM

 Messages: [ Previous | Next ]
 Steven Lord Posts: 18,038 Registered: 12/7/04
Re: how to split a matrix
Posted: Mar 7, 2013 10:28 AM

"Timothy Koh" <timothy_koh87@hotmail.com> wrote in message
news:kh9fi8\$hqk\$1@newscl01ah.mathworks.com...
> "James Tursa" wrote in message <kh9fap\$h62\$1@newscl01ah.mathworks.com>...
>> "Timothy Koh" <timothy_koh87@hotmail.com> wrote in message
>> <kh9eo1\$fmj\$1@newscl01ah.mathworks.com>...

>> > Hi
>> >
>> > I have a <39014400x1 double> matrix. How do i go about splitting it and
>> > merge it back together?
>> >
>> > Help is greatly appreciated
>> >
>> > Regards
>> > Timothy

>>
>> How do you want it split? E.g.,
>>
>> a = rand(39014400,1);
>> b = a(1:1000000); % split first part
>> c = a(1000001:end); % split second part
>> d = [b;c]; % join the pieces back together
>>
>> James Tursa

>
> Thanks James Tursa. Is it possible to split it like into number of
> segments i want? Eg. splitting it into 20 segments.

You haven't given the group sufficient information to answer definitively,
but I suspect the answer is yes. What limitations do you have on which
element goes into which segment?

First 39014400/20 elements in segment 1, next 39014400/20 elements in
segment 2, etc.?

Elements 1:20:39014400 in segment 1, elements 2:20:39014400 in segment 2,
etc.?

Elements 1 through 19 in segments 1 through 19 respectively and the rest in
segment 20?

Segments 1 through 19 each contain 1% of the data set chosen (without
replacement) at random, segment 20 contains the rest? [A division like this
might be useful in training/validation set division for neural network
training.]

See functions like RESHAPE, COLON, and RANDPERM for some of the tools that
may be useful to you depending on your chosen division method.

--
Steve Lord
slord@mathworks.com