## Divide a data set into sub data sets

### dav (view profile)

on 26 Sep 2013
Latest activity Commented on by dav

on 27 Sep 2013

### Azzi Abdelmalek (view profile)

Hi,

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.

Dav.

## Products

No products are associated with this question.

### Azzi Abdelmalek (view profile)

on 26 Sep 2013

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

Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

on 27 Sep 2013

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

Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

on 27 Sep 2013

If you want to avoid repetition

```A=1:100  % Example
data=reshape(A,[],20) % each column represent your part of data
[n,m]=size(data);
id=randi(m)
random_vector=data(:,id)
data(:,id)=[]
```
dav

### dav (view profile)

on 27 Sep 2013

thank you very much!

### Jan Simon (view profile)

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!

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi