Code & Data

Page Contents
Matlab code
Binomial Bayes Factor
Reading luminance values from a Minolta LS-1100 photometer
Detecting light flashes with the Response Time Box
Reading keypresses from the Cedrus RB-530 response box
Read, Parker & Cumming 2002
Read & Cumming 2004
Read & Cumming 2007
Hardingham et al. 2006, 2010
Read, Phillipson & Glennerster 2009
Nityananda, Tarawneh et al 2015
Signal detection theory
Code fragments for SMI RED eyetracker


Here, I have collected together various bits of Matlab code which may prove useful to other researchers. Some of these are code fragments such as how to read data from a Minolta LS-1100 photometer, others are sets of many files which should in theory enable you to reproduce results in my published work. If you have any problems using the code here, or reproducing the expected results, please get in touch and I’ll do my best to help.

NB Annoyingly, recent versions of Matlab are not quite backwards-compatible. One thing I get with all my old code is that the abbreviation “fonts” no longer works; you have to say “fontsize”. So you may need a search and replace on that.

Reading luminance values from a Minolta LS-1100 photometer


Binomial Bayes Factor

Here you can find information about Matlab code and a standalone executable for a GUI which enables you to calculate Bayes Factor for binomial data (e.g. M successes out of N attempts).

Detecting light flashes with the Response Time Box

See my notes on using the Response Time Box.

Reading keypresses from the Cedrus RB-530 response box

TestCedrus.m. This requires the function CedrusResponseBox.m, which was written by Mario Kleiner and Steve Elliot and slightly altered by me.

Read, Parker & Cumming 2002

A simple model accounts for the response of disparity-tuned V1 neurons to anti-correlated images.
Visual Neuroscience 19: 735-753

Read & Cumming 2004: Neural Computation

Understanding the cortical specialization for horizontal disparity.
Neural Computation Vol: 16(10) Pages: 1983-2020

Here is the code needed to generate the disparity distributions shown in Figure 5 of this paper. They are currently set up to generate Fig 5B.
First run DisparityDistrib_skeleton_rth.m.
This picks many different eye positions and retinal locations, and generates little line segments in disparity space.
It will create a matlab file with a name like DisparityDistrib_skel_rth_xi15_HVSD20_DSD8.mat.
Next run DisparityDistrib_flesh.m in order to convolve this infinitely narrow line segments with a Gaussian and generate a probability distribution suitable for plotting. It will create a matlab file with a name like DisparityDistrib_flesh_rth_xi15_HVSD10_DSD3_xlim1_ylim0.05.mat. Be warned, it is very slow though! (I’m sure it could be made more efficient.)
Finally after you have generated the two .mat files used in the paper, you can run PlotDisparityDistribution_zoomin.m to generate Fig 5.

Read & Cumming 2007

Read JCA, Cumming BG (2007)
Sensors for impossible stimuli may solve the stereo correspondence problem.
Nature Neuroscience, 10: 1322 – 1328
Supplementary material.
Comment on this paper in Nature‘s Research Highlights section, Nature, 449: 118.
Please be aware that the algorithms in this paper are very slow to run, because they require multiple convolutions of slightly different receptive fields with large images.

This directory should contain the code I used to generate Fig 3. (Actually, it’s the version of Fig 3 that appears in the Supplementary Material, with the true disparity being 0.06.) If I’ve remembered to include all the necessary files, then if you put all these files in the same directory, move to that directory in the Matlab command window and then type TestWithNoise_smalldisp it should start running. It generates many different noise images with the same disparity, and applies the four different algorithms to each one. After each image, it updates a histogram showing the estimated disparity for each algorithm. For our algorithm, only one bar of this histogram is non-zero: the estimated disparity is virtually always the correct stimulus disparity (error rate ~ 1 in 10,000 or so).
FitPentagon_fine.m generates Figure 5, basically, but be warned, it takes hours to run.


Hardingham et al. 2006, 2010

Quantal analysis Matlab code available here

Read, Phillipson & Glennerster 2009

Latitude and longitude vertical disparities
Journal of Vision, 9(13):11 1-37

The code to generate figures in this paper should be available as supplementary information on the journal’s website here, but there have been some problems accessing this, so I have also made it available here. Instructions on how to use the files are included in the paper.

Nityananda, Tarawneh, Jones, Busby, Herbert, Davies, Read (2015)

This paper reports the contrast sensitivity function for Sphodromantis lineola.
Here you can find the raw data for this paper, in Matlab format, and also an Excel file reporting the fitted thresholds for the individual insects and for the aggregate data pooled across individuals, using the methods reported in the paper.

Code fragments for SMI RED eyetracker

Blindness to background: an inbuilt bias for visual objects

O'Hanlon, CG and Read JCA ( 2016 )
Blindness to background: an inbuilt bias for visual objects

Developmental Science Vol: DOI: 10.1111/desc.12478 Pages: 1-23 [view on journal website] Pubmed ID : 27873433

A video abstract describing the main findings. Here is a press release by Aberystwyth University. Our complete Matlab code for these experiments, including the code for operating the RED50 eye tracker, is available here See also here.
1.6 MiB

For this paper, I needed Matlab code to control a RED50 remote eye tracker made by SMI. I was greatly helped by Frans Cornelissen’s iViewXToolbox, but it didn’t work for me out of the box. I fiddled around until I got my code working, but unfortunately for purposes of sharing, it’s all embedded in code to run the experiments we were doing. The complete code is available in the zip file linked to above, but here I’ve tried to pull out the key parts of my code in the hope it’s useful to anyone else trying this.

As described here, we had a PC running the experiment (displaying stimuli, collecting responses), connected via an ethernet cable to a laptop which controlled the eyetracker using SMI’s software. NB we had to turn off all the Windows firewall stuff in order for the two computers to communicate. The experiment was run using a GUI, ControlPanel.fig and its associated file ControlPanel.m. The experiment was started by typing “ControlPanel” in the Matlab window. DefineExptStructure.m handles the initial set-up. This creates the structure “expt”, which contains basically all the information about how the experiment is set up, the chosen parameters etc. This gets passed around to functions as needed. expt.ivx is a substructure which contains everything different functions need to know about the eyetracker.

Within ControlPanel, the key functions you may want to look at are:

  1. EyeTracker_Callback. This gets called when the user clicks the button to turn on eye tracking. It doesn’t do much but you’ll see that the state of the variable handles.EyeTracker is read by other functions to see if we are meant to be using the eyetracker or not.
  2. calibrate_Callback. This gets called when the user hits the button to calibrate. It in turn calls “UpdateExptStructure” to read off various parameters, generate a new filename to store the data etc. It then calls IVXCalibration3.m to actually run the calibration.
  3. startexpt_Callback. This is called when the user hits the button to run an experiment. It looks up on the GUI what experiment the user wants to run this time and then calls the appropriate program (you will insert your function here!). Then after the participant has made their response, we call AfterTrial.m. If you just look through that using “find” to search for IVX, you’ll see the relevant commands for specifying the format of the eyetracker data, start streaming it from the eyetracker, stop streaming etc. It also calls a function GazeData.m, which has some code that may be relevant to you. It reads in the eye position data, throws away the (0,0) values and draws the gaze path (without any further correction for blinks).These files beginning “IVX…” are the ones relating specifically to communicate with the eyetracker, which as you’ll see are basically Frans Cornelissen’s code plus with a few tweaks I found I had to make.

I realise these code fragments are a terrible mess for anyone else trying to get their head around them, but hey when you’re stuck anything is useful!

Signal detection theory

This Excel spreadsheet, written by Dr Ignacio Serrano-Pedraza, makes signal detection theory easy. Simply enter the values in the response matrix (hits, false alarms, correct rejects and misses) and it will compute ROC curves, d-prime and beta values for you. Right-click the above link and use “Save target as…” to download the excel file.

4 thoughts on “Code & Data

  1. I am writing to you hoping you could help me with getting your script to work (CedrusResponseBox.m).

    When I try to initialise the connection with the box, the script returns the following error:

    handle = CedrusResponseBox(‘Open’, ‘COM3′);
    Undefined function or variable ‘IsOctave’.

    Error in CedrusResponseBox (line 409)
    if IsOctave || IsOSX

    line 409 reads:

    if IsOctave || IsOSX
    error(‘Sorry, the Apple-OS/X operating system and/or GNU Octave are not yet supported.’);

    I am using CEDRUS RB- 730 response box, under 32-bit Windows XP. I do not have much experience in changing the runtime, and I am not sure whether it would help in this case. I would appreciate if you could point me to the right direction.

    I am looking forward to hearing from you.

    Best regards,


  2. Hi Maciej,
    It looks as if you are getting this error because the function IsOctave isn’t on your Matlab path. This function is part of the Psychophysics toolbox (PTB). It’s probably best to install PTB before running any of my / Mario’s code, as we are likely to call PTB functions. Instructions on how to install PTB are here:

    Alternatively, if you are not running Octave or OSX, you could try just deleting those lines.

    Good luck with the Cedrus!

    Best wishes,


  3. Hi Jenny
    Thanks for sharing your knowledge
    I try to use the “GazeData.m” to skape the eye tracker outpouts (0,0)
    But I cannot understand your parameters that you use in the function
    Could you please help me?

  4. Hi Azar,
    Yes, I’m afraid those parameters (expt,stimulus,data,jtrial,trial) are very specific to my own code. You can look at the full experiment code in the .zip file to see how they are used, but I don’t think that’s going to be very helpful to you.

    I shared GazeData.m really so people could see how I used the IVXtoolbox in my code – e.g. REDdata = IVXreceive(expt.ivx) to get a line of input from the eyetracker, and then the subsequent lines of code to show how I processed it and read off the time and monocular/binocular eye positions.

    Is that any help?



Leave a Reply

Your email address will not be published. Required fields are marked *