MATLAB Answers


Divide a data set into sub data sets

Asked by dav
on 26 Sep 2013
Latest activity Commented on by dav
on 27 Sep 2013


I am running a simulation program.

There, in every simulation run it creates a data set of size T. I would like to know if there's a loop I can use to divide this data set into 20 sub data sets of equal size and randomly choose a data set, among the 20 sub data sets, to be used in a different pat of the program.

any help is greatly appreciated.




No products are associated with this question.

2 Answers

Answer by Azzi Abdelmalek
on 26 Sep 2013
 Accepted answer

A=1:100  % Example
data=reshape(A,[],20) % each column represent your part of data


I do not know what (sample a vector under sampling with replacement) means. The code pick randomly a vector from the 20 parts, but it can pick the same another time

If you want to avoid repetition

A=1:100  % Example
data=reshape(A,[],20) % each column represent your part of data

thank you very much!

Answer by Jan Simon
on 27 Sep 2013

The question is not clear. You have T "data sets" (what ever this mean) and want to divide it in 20 "sets" of equal size. Is T dividable by 20? Should the new data sets contain repetitions, e.g. is this allowed:

aNewDataSet = [T(1), T(1), T(3:end)]

Should the new data sets be elementwise distinct or is this allowed:

newDataSet(1) = [T(1), T(3:10)]
newDataSet(2) = [T(1), T(4:11)]

When only one data set is used afterwards, why creating 20 of them at first?


Join the 15-year community celebration.

Play games and win prizes!

Learn more
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

MATLAB Academy

New to MATLAB?

Learn MATLAB today!