MGL

Mgl is a suite of mex/m files for displaying visual psychophysics stimuli and writing experimental programs in Matlab. Runs on Mac OS X and is compatible with latest versions of the Mac OS (Ventura as of this writing 8/11/2023). It is based on Metal, Apple's low-level graphics card libarary. See here for a list of publications that have used mgl and how to cite use of mgl in your manuscript!

A quick overview

mgl is a set of matlab functions for displaying full screen visual stimuli from matlab. It is based on Apple Metal with simple functions that can be used to code various kinds of visual stimuli. It can be used on Mac OS X systems only.

The best way to see whether it will be useful to you is to try out the mglTest programs and also the sample experiment testExperiment. A basic “hello world” program can be written in four lines:

  % Open the screen, 0 specifies to draw in a window. 
  % 1 would be full screen in the main display
  % 2 would be full screen in a secondary display, etc... 
  mglOpen(0);
 
  % Select the coordinate frame for drawing
  % (e.g. for a monitor 57 cm away, which has width and height of 16 and 12 cm). 
  mglVisualAngleCoordinates(57,[16 12]);
 
  % Draw the text in the center (i.e. at 0,0)
  mglTextDraw('Hello World!',[0 0]);
 
  % The above is drawn on the back-buffer of the double-buffered display
  % To make it show up you flush the display.
  % This function will wait till the end of the screen refresh
  mglFlush;

When finished with displaying the stimuli, you simply close the screen:

mglClose;