Index error running Psychtoolbox experiment

2 visualizzazioni (ultimi 30 giorni)
Dear Community,
I am running my experiment using Psychtoolbox. Unfortunately, I cannot share the whole script here, but generally it's a centre-out reaching task where my participants use a joystick to reach targets. The joystick trajectory is being tracked with high temporal resolution and saved.
The tasks is presented using Psychtoolbox-3 (3.0.19) running on the MATLAB platform (2021b) in ubuntu (22.04).
The script works somewhat unstable. In 50 percent of cases it runs smoothly without any issues. In the other 50 percent it crushes with the following error message:
Identifier: MATLAB:badsubscript (line 643)
Error: Index in position 1 exceeds array bounds. Index must not exceed 552.
Error in function TextSize: Invalid Window (or Texture) Index provided: It doesn't correspond to an open window or texture.
Did you close it accidentally via Screen('Close') or Screen('CloseAll') ?
Error using Screen
Usage:
oldTextSize=Screen('TextSize', windowPtr [,textSize]);
Error in C_cued_cursor_rotation_joystick_noCentre (line 727)
Screen('TextSize',wPtr, 40);
Here's a few lines of my script with line 643 highlighted:
motion(:,9) = [NaN; ((velo/pix_per_mm)/1000)]; %convert velocity units to m/s
%store raw data
trialDat{trial} = motion;
%extract reach data
reachDat{trial} = motion(move_loc:endLoc,:); % LINE 643
%get velocity trend
reachDat{trial}(:,10) = trenddecomp(reachDat{trial}(:,9));
%identify max velocity from trend data
[maxVelo, maxLoc] = max(reachDat{trial}(:, 10));
I'm not a great expert in Matlab unfortunetely. What bugs me is that the script crushes at random time points. Sometimes after 50 trials, sometimes after 450+. And there seems to be nothing different im terms of participant's performance compared to other trials.
Do you have any ideas what can cause this issue?
And why it doesn't crush from the very first trial?

Risposta accettata

Karanjot
Karanjot il 4 Giu 2024
Hi Ekaterina,
The errors in your Psychtoolbox script on MATLAB suggest two primary issues:
  1. Index Exceeds Array Bounds:
  • This is caused by attempting to access an index of the motion array beyond its size at
reachDat{trial} = motion(move_loc:endLoc,:);
  • The endLoc variable likely exceeds the size of the motion array, possibly due to variable joystick data collection.
  • To solve this, ensure endLoc is within bounds before accessing the array:
if endLoc > size(motion, 1)
endLoc = size(motion, 1); % Adjust to max index
end
2. Invalid Window (or Texture) Index Provided:
  • The error indicates wPtr references a closed or invalid window. To resolve this, verify the window wPtr is open before making calls that depend on it
if Screen('WindowKind', wPtr) ~= 1
error('Window referenced by wPtr is not open.');
else
Screen('TextSize', wPtr, 40);
end
The instability likely stems from dynamic data variations across trials. Implement additional checks for dynamic variables (motion, move_loc, endLoc) and manage resources (windows, textures) carefully to avoid unintended closures.

Più risposte (0)

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by