Hi all,

I have an issue with movie presentation in PTB. I am using Matlab R2021a and PTB 3.0.17 on a Windows 10 operating system.

What I want to do is the following:

- I start a video with the duration of several minutes.
- I want to squeeze a number of x trials into this video. During the trials I overlay the currently running video with additional images.
- Each trial has the same structure. So I am wondering if I could iterate through trial 1:x while I continue presenting the video.

My current approach is to make a dummy variable that counts the number of texture I am currently at (so the textures increase while the video plays). Then I define ranges for my single trials in which my additional actions should happen. However, triggering the trials using a for loop results in error messages.

This is the structure of my code:

movie = Screen(‘OpenMovie’, win, movname);

rate = 1;

Screen(‘PlayMovie’, movie, rate);

tex_num = 0

while ~KbCheck

tex = Screen(‘GetMovieImage’, win, movie);

if tex<=0

break;

end

tex_num = tex_num + 1;

```
if tex_num < 100
Screen('PlayMovie', movie, rate);
Screen('DrawTexture', win, tex);
Screen('Flip', win);
Screen('Close', tex);
temp_low = tex_num;
temp_high= tex_num + 15;
if tex<=0
break;
end
```

%%% trial 1

```
elseif tex_num > temp_low && tex_num < temp_high
additional.image = Screen('MakeTexture', win, myimage);
Screen('DrawTexture', win, tex);
Screen('DrawTexture', win, additional.image);
Screen('Flip', parm.exp.scr.w);
Screen('Close', tex);
temp_low_1 = tex_num;
temp_high_1 = tex_num + 15;
if tex<=0
break;
end
```

%%% trial 2

```
elseif tex_num > temp_low_1 && tex_num < temp_high_1
additional.image = Screen('MakeTexture', win, myimage);
Screen('DrawTexture', win, tex);
Screen('DrawTexture', win, additional.image);
Screen('Flip', parm.exp.scr.w);
Screen('Close', tex);
temp_low = tex_num;
temp_high= tex_num + 15;
if tex<=0
break;
end
```

etc.etc.

This is of course comletely unelegant. I don’t want to hard code every single trial but repeat the process over x trials.

I’m kind of stuck so I would really appreciate your advise!

Thanks a lot!