I’ve translated some code from a Matlab script into Julia, but I’m finding it running much slower…

The culprit loop is:

```
for i::Int16 = 1 : n_acts
n_ages::Int16 = m["max_age"][i]
if n_ages > 1
idx = v[i] # variable indexes
perm_give = -1*I(n_ages-1)
perm_take = I(n_ages-1)
# insert permissions in full matrix
for t= 1 : (n_yr-1)
#a_temp = zeros((n_ages-1), n_cols) #This added 5 seconds over the following line!
a_temp = fill(Int(0),((n_ages-1), n_cols)) # temporary permission matrix
a_temp[:, idx[t,1] : idx[t,n_ages-1]] = perm_give
a_temp[:, idx[t+1,2] : idx[t+1,n_ages]] = perm_take
#here comes the slow part....
a_perm = cat(a_perm, a_temp;dims=1)
end # t loop
end # if
end # activity loop
```

As a_perm grows it gets very slow in Julia, whereas Matlab doesn’t seem to have any issues…

Note also the commented line creating a_temp. For some reason it was even slower using the zeros function compared with fill. This helped a bit, but it’s still way too slow… How can I speed things up???