# Invalid MEX file error

**URL:** <https://psychtoolbox.discourse.group/t/invalid-mex-file-error/3303>\
**Category:** Bugs & Features\
**Created:** [July 20, 2020, 4:40pm UTC](https://psychtoolbox.discourse.group/t/invalid-mex-file-error/3303 "2020-07-20T16:40:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DBermudez0](https://avatars.discourse-cdn.com/v4/letter/d/3ab097/32.png) [@DBermudez0](https://psychtoolbox.discourse.group/u/DBermudez0)\
**Post date:** [July 20, 2020, 4:40pm UTC](https://psychtoolbox.discourse.group/t/invalid-mex-file-error/3303/1 "2020-07-20T16:40:24Z")

</div>

function ContrastPsychometricFunction  
clear all;  
Screen(‘Preference’,‘VBLTimestampingmode’, 1);  
Screen(‘Preference’, ‘SkipSyncTests’, 1);  
%%Display Setup Module  
% Define display parameters  
%clear all;  
whichScreen = max(Screen( ‘screens’ ));  
p.ScreenDistance = 30; % in inches  
p.ScreenHeight = 15; % in inches  
p.ScreenGamma = 2; % from monitor calibration  
p.maxLuminance = 100; % from monitor calibration  
p.ScreenBackground = 0.5;  
% Open the display window, set up lookup table, and hide the  
% mouse cursor  
if exist( ‘onCleanup’ , ‘class’ ), oC\_Obj = onCleanup(@()sca); end  
% close any pre-existing PTB Screen window  
% Prepare setup of imaging pipeline for onscreen window.  
PsychImaging( ‘PrepareConfiguration’ ); % First step in starting pipeline  
PsychImaging( ‘AddTask’ , ‘General’ , …  
‘FloatingPoint64BitIfPossible’ );  
% set up a 32-bit fl oatingpoint framebuffer  
PsychImaging( ‘AddTask’ , ‘General’ , …  
‘NormalizedHighresColorRange’ );  
% normalize the color range ([0, 1] corresponds  
% to [min, max])  
PsychImaging( ‘AddTask’ , ‘General’ , ‘EnablePseudoGrayOutput’ );  
% enable high gray level resolution output with  
% bitstealing  
PsychImaging( ‘AddTask’ , ‘FinalFormatting’ , ‘DisplayColorCorrection’ , ‘SimpleGamma’ );  
% setup Gamma correction method using simple power  
% function for all color channels  
[windowPtr p.ScreenRect] = PsychImaging( ‘OpenWindow’, whichScreen, p.ScreenBackground);  
% Finishes the setup phase for imaging pipeline  
% creates an onscreen window, performs all remaining  
% configuration steps  
PsychColorCorrection( ‘SetEncodingGamma’ , windowPtr, 1/ p.ScreenGamma);  
% set Gamma for all color channels  
HideCursor; % Hide the mouse cursor  
% Get frame rate and set screen font  
p.ScreenFrameRate = FrameRate(windowPtr);  
% get current frame rate  
Screen( ‘TextFont’ , windowPtr, ‘Times’ );  
% set the font for the screen to Times  
Screen( ‘TextSize’ , windowPtr, 24); % set the font size  
% for the screen to 24  
%%Experimental Module  
% Specify general experimental parameters  
nContrast = 7; % number of contrast levels in experiment  
repeats = 100; % number of trials to repeat for each contrast  
nTrials = repeats \* nContrast; % compute total number of trials  
p.randSeed = ClockRandSeed; % use clock to set random number generator  
keys = { ‘1’ ‘2’ ‘esc’ }; % specify response keys for the two intervals and to break  
% Specify the stimulus  
p.stimSize = 6; % image diameter in visual degree  
p.sf = 1; % spatial frequency in cycle/degree  
conRange = [0.0025 0.04]; % lowest and highest tested contrasts  
p.stimDuration = 0.1; % stimulus duration in seconds  
p.interval = 1; % seconds between two intervals of a trial  
p.ISI = 0.5; % seconds between trials  
% Compute stimulus parameters  
ppd = pi/180 \* p.ScreenDistance / p.ScreenHeight \* p.ScreenRect(4);  
% compute pixels per degree from  
% p.ScreenDistance and p.ScreenHeight  
m = round(p.stimSize \* ppd /2) \* 2; % stimulus size  
% in pixels  
fixRect = CenterRect([0 0 1 1] \* 8, p.ScreenRect);  
% define an 8 x 8 pixel fixation  
% create another fixation stimulus of horizontal and  
% vertical cross hairs outside the area of the sine wave  
% pattern. Crosshairs will be displayed during display  
% intervals  
fixLen = 32; % length of fixation in pixels  
fixXY = [[-1 0 0 1] \* fixLen + [-1 -1 1 1] \* m/2 + …  
p.ScreenRect(3)/2 [1 1 1 1]\*p.ScreenRect(3)/2; …  
[1 1 1 1]\*p.ScreenRect(4)/2 [-1 0 0 1] \*fixLen + …  
[-1 -1 1 1] \* m/2 + p.ScreenRect(4)/2];  
p.contrasts = logspace(log10(conRange(1)), log10(conRange(2)), nContrast);  
% use logspace function to choose nContrast contrasts  
% (7) at log intervals between the minimum and  
% maximum specifi ed contrasts  
sf = p.sf / ppd; % compute spatial frequency in  
% cycles per pixel  
tex = CreateProceduralSineGrating(windowPtr, m, m, [[1 1 1]\*p.ScreenBackground 0], m/2, 0.5);  
% “ CreateProceduralSineGrating ” is a psychtoolbox  
% function to create a procedural texture for drawing  
% sine grating stimulus patches on the GPU  
% Initialize a table to set up experimental conditions  
p.recLabel = { ‘trialIndex’ ‘contrastIndex’ ‘whichInterval’ …  
‘respCorrect’ ‘respTime’ };  
% labels the columns of the data recording array rec  
rec = nan(nTrials, length(p.recLabel));  
% matrix rec is initialized as an nTrials x 5 of NaN  
rec(:, 1) = 1 : nTrials;  
% initialize trial numbers from 1 to nTrials  
contrastIndex = repmat(1 : nContrast, repeats, 1);  
% use repmat to cycle thru contrast #s  
intervalIndex = ones(size(contrastIndex)) \* 2;  
% first set all trials to 2nd interval  
intervalIndex(1 : repeats / 2, 🙂 = 1;  
% change fi rst half to 1  
[rec(:, 2) ind] = Shuffle(contrastIndex(:));  
% shuffle contrast indexes to randomize  
rec(:, 3) = intervalIndex(ind);  
% shuffle interval indexes in the same order  
% Prioritize display to optimize display timing  
Priority(MaxPriority(windowPtr));  
% Start experiment with instructions  
str = sprintf( ‘Press 1 or 2 for the first or second interval.\n\nPress SPACE to start.’ );  
DrawFormattedText(windowPtr, str, ‘center’ , ‘center’ , 1);  
% Draw Instruction text string centered in window  
Screen( ‘Flip’ , windowPtr);  
% flip the text image into active buffer  
WaitTill( ‘space’ ); % wait till space bar is pressed  
Screen( ‘FillOval’ , windowPtr, 0, fixRect);  
% create a black fi xation dot  
Secs = Screen( ‘Flip’ , windowPtr);  
% flip the fixation image into active buffer  
p.start = datestr(now); % record start time  
% Run nTrials trials  
for i = 1 : nTrials  
con = p.contrasts(rec(i, 2));  
% use contrast index from rec to set contrast  
% for this trial  
flipSecs = Secs + p.ISI + [0 p.interval];  
% define the start time of the two intervals  
for j = 1 : 2 % two intervals  
if rec(i, 3) == j  
% draw the grating in the interval defi ned  
% in rec(i,3) only  
Screen( ‘DrawTexture’ , windowPtr, tex, [], [], …  
0, [], [], [], [], [], [180 sf con 0]);  
end % draw the sine grating with phase 180,  
% spatial frequency, and contrast  
Screen( ‘DrawLines’ , windowPtr, fixXY, 3, 0.3);  
% add the fixation crosshairs  
t0 = Screen( ‘Flip’ , windowPtr, flipSecs(j));  
% show the stimulus and return the time  
Screen( ‘Flip’ , windowPtr, t0 + p.stimDuration);  
% turn off the stimulus by fl ipping to  
% background image after p.stimDuration secs  
end  
Screen( ‘FillOval’ , windowPtr, 0, fixRect);  
% draw the smaller centered fixation  
Screen( ‘Flip’ , windowPtr, t0 + 0.25 + p.stimDuration);  
% show small fixation briefly to cue the  
% observer to respond with the interval  
[key Secs] = WaitTill(keys);  
% wait for response, return key and response time  
if iscellstr(key), key = key{1}; end  
% take the fi rst response in case of multiple  
% key presses  
if strcmp(key, ‘esc’ ), break; end  
% check if response is \< escape \> to stop experiment  
rec(i, 4 : 5) = [str2double(key)==rec(i, 3) Secs-t0];  
% record correctness and respTime  
if rec(i, 4), Beeper; end % beep if correct  
end  
p.finish = datestr(now); % record fi nish time  
save ContrastPsychometricFunction\_rst.mat rec p;  
% save the results  
%%System Reinstatement Module  
Priority(0); % restore priority  
sca; % close display window and textures,  
% and restore the original color lookup table

I am trying to run this ConstrastPsychometricFunction script. However, it exits with the following error:  
Invalid MEX-file ‘/home/dbermudez/Documents/MATLAB/Psychtoolbox-3/Psychtoolbox/PsychBasic/moglcore.mexa64’:  
libglut.so.3: cannot open shared object file: No such file or directory

Error in InitializeMatlabOpenGL (line 186)  
moglcore(‘DEBUGLEVEL’, debuglevel);

Error in PsychImaging\>PostConfiguration (line 3393)  
InitializeMatlabOpenGL([], [], 1);

Error in PsychImaging (line 2373)  
PostConfiguration(reqs, win, clearcolor, slavewin);

Error in ContrastPsychometricFunction (line 34)  
[windowPtr p.ScreenRect] = PsychImaging( ‘OpenWindow’, whichScreen, p.ScreenBackground);

Error using xslt\>locTransformer (line 160)  
Could not find associated stylesheet

Error in xslt (line 91)  
xProcessor = locTransformer(varargin{2},xSource,xUtil,errorListener,uriResolver);

Error in help2html (line 68)  
outStr = xslt(dom,xslfile,’-tostring’);

---

<div class="post-metadata">

**Author:** ![dcnieho](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@dcnieho](https://psychtoolbox.discourse.group/u/dcnieho)\
**Post date:** [July 20, 2020, 5:08pm UTC](https://psychtoolbox.discourse.group/t/invalid-mex-file-error/3303/2 "2020-07-20T17:08:42Z")

</div>

There’s quite a lot of information missing in this post: what matlab? what OS? What PTB version?

The error seems to suggest you are missing some dependency. Did you follow the install instructions to the letter and also install the needed dependencies? libglut to be exact is missing, but you may well be missing more than that.
