I to do some indexing, something like what follows:

```
for c=1:size(params,1)
for d=1:size(data,2)
if params(c,8)==1
value1(c,d)=data(params(c,11),d);
elseif params(c,8)==2
value2(c,d)=data(params(c,11),d);
elseif params(c,8)==3
value3(c,d)=data(params(c,11),d);
end
end
end
```

The problems with this is that if we have `params(:,8)=1,3,1,3,2,3,1...`

then **value1** will contain all zeros in rows 2, 4, 5, 6, etc. These are the rows that do not have 1 in column 8 in `params`

. Similarly, **value2** will contains all zeros in rows 1, 2, 3, 4, 6, 7... and **value3** will contain all zeros in row 1, 3, 5, 7, .... Could anyone tell me how to index so I don't have 'gaps' of zeros in between rows? Thanks!

Edit; below is a sample dataset:

**data** (1080x15 double)

```
168 432 45 86
170 437 54 82
163 423 52 83
178 434 50 84
177 444 42 87
177 444 58 85
175 447 48 77
184 451 59 86
168 455 52 104
174 437 62 88
175 443 55 85
179 456 51 92
168 450 73 82
175 454 60 68
```

**params** (72x12 double - we are interested in only column 8 and 11 ) so I'm showing only column 8-11 for the sake of space:

```
1 10 15 1
3 12 16 16
2 10 15 32
3 12 16 47
1 8 14 63
2 10 15 77
2 8 14 92
3 10 15 106
1 12 16 121
3 8 14 137
2 10 15 151
```

The expected output for **value1, value2, and value3** should be 24x15. This is because there are 15 columns in data and value 1, 2, 3 occur 24 times each in column 8 in `params`

.