Question: ```
filename = 'SOMETHING';
eval(['load ' filename]);

eval(['load ' filename '_vid1'])
vid123=permute(vid,[2 1 3]);
size(vid)

eval(['load ' filename '_vid2'])
vid123(:,:,(size(vid123,3)+1):(size(vid123,3)+size(vid,3)))=permute(vid,[2 1 3]);
size(vid)

```

I know it has to do with loading a file and finding other files with the same name and '\_vidX' appended to it, but what does line 7 exactly do/mean?

Answer: 
Carrying on from Daniel's answer, your question is stemming from the fact that you don't quite know how `permute` works. The goal of [`permute`](http://www.mathworks.com/help/matlab/ref/permute.html) is to rearrange the dimensions of a matrix but leave the size of the matrix intact. You specify the matrix you want to "permute" as well as a vector that tells you which input dimensions map to the output.

What `permute(vid, [2 1 3]);` means is that the second dimension of the input goes to the first dimension of the output. The first dimension of the input goes to the second dimension of the input, and the third dimension stays the same. The effect of this is that `vid` is a 3D matrix where each 2D slice /frame is **transposed** while maintaining the same amount of slices / frames in the final output. You are swapping the second and first dimensions which is essentially what the transpose does. 

Therefore, the first load statement loads in your frames through the variable `vid`, and `vid123` originally has some number of frames where each frame is transposed - these correspond to the first video. After this, you are loading in the second video where `vid` gets overwritten with the frames from the second video. You then add those frames on top of `vid123`. Therefore, you are simply piecing the frames from the first frame and second frame together - transposed creating one larger video.

I would highly recommend you resave this so that both videos are separated clearly by different variables, or perhaps have a structure that contains both of the videos together. Having the variable `vid` being stored in two separate files is problematic.

Something like this would work:

```
load([filename '_vid1']);
vid1 = vid;
load([filename '_vid2']);
vid2 = vid;
clear vid;
save videos;

```

... or even this would work:

```
load([filename '_vid1']);
s.vid1 = vid;
load([filename '_vid2']);
s.vid2 = vid;
clear vid;   
save videos;

```

In the first version, both videos are stored in separate variables `vid1` and `vid2` and the second version, both videos are saved in one structure.
Just to rewrite the 7th line how it should be rewritten:

```
vid123=cat(3,vid123,permute(vid,[2 1 3])

```

It concatenates both variables among the 3rd dimension. In case you intend to understand the original line, just put the end statement wherever it should be used and it is suddenly much more readable:

```
vid123(:,:,end+1:end+size(vid,3))=permute(vid,[2 1 3]);

```

Using `end+1:end+size(vid,3)` it inserts `size(vid,3)`-many new slices into the 3d matrix `vid123`