Hi,
I am trying to code my EEG experiment in Matlab using PSB on a Window 11. I played video’s and sounds before on this computer using this code. But suddenly, Matlab crashes when running the code, as such I cannot see the error causing the crash.
Can someone help me discover the problem, that would help me so much ? (I’ll post pieces of the code, which are of importance)
function visualonly_metreactie ()
InitializePsychSound;
PsychDefaultSetup(2);
AssertOpenGL;
screens = Screen('Screens');
screenNumber = max(screens);
screenSize = Screen('Rect', screenNumber);
fig = figure('MenuBar', 'none', 'Color', [0 0 0], 'Resize', 'on');
set(fig, 'WindowStyle', 'modal');
set(fig, 'WindowState', 'fullscreen');
set(fig, 'Toolbar', 'none');
white = [1 1 1];
black = [0 0 0];
% Get screen size and open black background
% Ctrl + F11 to close fullscreen
screens = Screen('Screens');
screenNumber = max(screens);
% Windowed screen
% [window, windowRect] = PsychImaging('OpenWindow', screenNumber, black, [0 0 800 600]);
% Full-width screen:
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, black);
ifi = Screen('GetFlipInterval', window);
Screen('BlendFunction', window, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
[~, ~] = Screen('WindowSize', window);
[~, ~] = RectCenter(windowRect);
Screen('TextSize', window, 30);
Screen('TextFont', window, 'Courier');
DrawFormattedText(window, 'Are you ready for round 1?\n\nPress the spacebar to start!', 'center', 'center', white);
% Flip to the screen
Screen('Flip', window);
while 1
[keyIsDown, ~, keyCode] = KbCheck;
if keyIsDown && keyCode(KbName('space'))
break;
end
end
% Full-width screen:
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, black);
ifi = Screen('GetFlipInterval', window);
Screen('BlendFunction', window, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
[~, ~] = Screen('WindowSize', window);
[~, ~] = RectCenter(windowRect);
Screen('TextSize', window, 70);
presSecs = 0.5;
waitframes = round(presSecs / ifi);
currentNumber = 3;
topPriorityLevel = MaxPriority(window);
Priority(topPriorityLevel);
vbl = Screen('Flip', window);
while currentNumber >= 0
numberString = num2str(currentNumber);
DrawFormattedText(window, numberString, 'center', 'center', white);
vbl = Screen('Flip', window, vbl + (waitframes - 1) * ifi);
currentNumber = currentNumber - 1;
end
%----------------------------------------------------------------------
% Run the experiment
%----------------------------------------------------------------------
dirPath = 'C:\Users\Administrateur\Desktop\MATLAB\22_Pubert_Hear\pilot';
BAfileName = 'BAvideo_sound.mp4';
DAfileName = 'DAvideo_sound.mp4';
BAmoviename = fullfile(dirPath,BAfileName);
DAmoviename = fullfile(dirPath,DAfileName);
BA = VideoReader ('BAvideo_sound.mp4');
DA = VideoReader ('DAvideo_sound.mp4');
% Define StimuliList:
StimuliList = [1 1 1 2 1 1 1 1 1 1 2 1]';
ReactionList = [0 0 1 0 0 0 0 0 1 0 0 0];
R = length(ReactionList);
StimuliMatrix = zeros(R,3);
StimuliMatrix(:,1) = StimuliList;
StimuliMatrix(:,2) = ReactionList;
% Load the reaction image
white = [1 1 1];
emoji = imread('emoji1.png');
emoji = imresize(emoji, [10, 10], 'bicubic');
[emojiWidth, emojiHeight] = size(emoji);
[screenWidth, screenHeight] = Screen('WindowSize', window);
emojiX = screenWidth/2 - emojiWidth/2;
emojiY = screenHeight/2 - emojiHeight/2;
emoji_tex = Screen('MakeTexture', window, emoji);
% Calculate the position of the texture
emojiX = screenWidth/2 - emojiWidth/2;
emojiY = screenHeight/2 - emojiHeight/2;
% Reaction-task
reaction_output = zeros(1,15);
index = 1;
start_time = GetSecs(); %time of every stimuli played
deviceNumber = -1;
KbQueueCreate(deviceNumber);
KbQueueStart(deviceNumber);
--------- until here everything works ----------
for i = 1:size(StimuliMatrix,1)
% Get the current stimulus and reaction values
currentStimulus = StimuliMatrix(i, 1);
currentReaction = StimuliMatrix(i, 2);
% If the current stimulus is 1 and the current reaction is 0, play BA
if currentStimulus == 1 && currentReaction == 0
StimuliMatrix(i,3) = GetSecs()-start_time;
BAmovie = Screen('OpenMovie', window, BAmoviename);
Screen('PlayMovie', BAmovie, 1, [], 0);
while hasFrame(BA)
tex_ba = Screen('GetMovieImage', window, BAmovie);
if tex_ba <= 0
break;
end
Screen('DrawTexture', window, tex_ba);
Screen('Close', tex_ba);
Screen('Flip', window);
end
Screen('PlayMovie', BAmovie, 0, [], 0);
Screen('CloseMovie', BAmovie);
---------- the moment the video needs to play, it crashes, rest of the code is not provided, cause similar to first if -------------------
Thank you for your time,
Ellen