Psychtoolbox- Error Using Screen

Hi everyone, I'm encountering an issue with a section of code from a script. It keeps closing out with an error, and I'm not sure why. The error message reads as follows:
Error using Screen
Usage:
Screen('DrawTexture', windowPointer, texturePointer [,sourceRect] [,destinationRect] [,rotationAngle] [, filterMode] [, globalAlpha] [, modulateColor] [, textureShader] [, specialFlags] [,
auxParameters]);
Error in memcongr (line 802)
Screen('DrawTexture', window, leftStimuli{iTrial}, [], LeftPatch{iTrial});
The variables leftStimuli & LeftPatch are defined as:
leftStimuli = cell(1,nruns);
LeftPatch = cell(1,length(rightselection{oldtrialsperrun}));
Also, these variables are defined as:
oldtrialsperrun:
oldtrialsperrun = 5;
luretrialsperrun= 3;
nTrialsTotal = oldtrialsperrun + luretrialsperrun;
rightselection
images_encoding_stim = Shuffle(stimuli);
leftStimuli = cell(1,nruns);
RightStimuli = cell(1,nruns);
% Ensure the equality of the number of stimuli
total_stimuli = length(images_encoding_stim);
half_stimuli = floor(total_stimuli / 2);
% Divide into two groups: right position and left position
rightselection = images_encoding_stim(1:half_stimuli);
leftselection = images_encoding_stim(half_stimuli+1:end);
clear half_stimuli
% Divide for each run (here you get a code with the stimuli you need to present on the right and left sides)
for irun = 1:nruns
stimuliPerRunRight{irun} = {rightselection(1+(irun-1)*oldtrialsperrun : irun*oldtrialsperrun)};
stimuliPerRunLeft{irun} = {leftselection(1+(irun-1)*oldtrialsperrun : irun*oldtrialsperrun)};
end
Thank you very much for everything. I've been stuck with this error for a couple of months. I'm very willing and open to answering questions about any part of the code in order to get it working.

2 Comments

The code posted does not show setting of leftStimuli or RightStimuli, so as far as we know leftStimuli{iTrial} is an empty cell.
You are absolutely right, the variables are not completely described so that it can be solved.
Thank you very much for your assistance, best regards.

Sign in to comment.

 Accepted Answer

Umar
Umar on 2 Jul 2024
Hi Martin,
Upon examining the code, it appears that the leftStimuli variable is defined as a cell array with a size of 1xnruns. However, in the Screen('DrawTexture') function call, it is being accessed using the index iTrial. This suggests that there might be an indexing issue, where the iTrial variable is exceeding the size of the leftStimuli array. So, you need to ensure that the iTrial variable is within the valid range of indices for the leftStimuli array. You can do this by modifying the loop where the Screen('DrawTexture') function is called. So, my suggestion would be adding the check if iTrial <= length(leftStimuli), which will ensure that the Screen('DrawTexture') function is only called when iTrial is within the valid range of indices for the leftStimuli array. If iTrial exceeds the valid range, an error message is displayed. Let me know if you need further assistance.

3 Comments

Hi Umar,
First of all, thank you so much for your response. I've incorporated the following code into my script:
if iTrial <= length(leftStimuli)
Screen('DrawTexture', window, leftStimuli{iTrial}, [], LeftPatch{iTrial});
end
However, I’m still encountering an error even with this code in place. :(
Error using Screen
Usage:
Screen('DrawTexture', windowPointer, texturePointer [,sourceRect] [,destinationRect] [,rotationAngle] [, filterMode] [, globalAlpha] [, modulateColor] [, textureShader] [, specialFlags] [,auxParameters]);
Error in memcongr (line 803)
Screen('DrawTexture', window, leftStimuli{iTrial}, [], LeftPatch{iTrial});
Thank you very much in advance, best regards!
Umar
Umar on 2 Jul 2024
Moved: Voss on 2 Jul 2024
Hi Martin,
No problem, Martin. It sounds like you encountered another error. To fix this error, ensure that the parameters passed to the Screen('DrawTexture') function are in the correct order and format. The correct syntax for the function is as follows:
Screen('DrawTexture', windowPointer, texturePointer [,sourceRect] [,destinationRect] [,rotationAngle] [,filterMode] [,globalAlpha] [,modulateColor] [,textureShader] [,specialFlags] [,auxParameters]);
Make sure that each argument is provided in the expected sequence and that the data types match the function's requirements.
In the context of the provided code snippet, the correction would be:
if iTrial <= length(leftStimuli) Screen('DrawTexture', window, leftStimuli{iTrial}, [], [], [], [], [], [], []); end
Ensure that the empty brackets [] are used for optional parameters that are not needed in your case. Also, you can modify the code to include a check to ensure that iTrial is within the bounds of the leftStimuli array before attempting to draw the texture.
Thank you very much for the answer Umar,
Indeed the error was the one you mentioned, it seems that the variables were not right. I did an error analysis and detected the error with what you proposed.
Thank you very much for everything

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!