MATLAB and Graphical User Interfaces: Tools for Experimental Management
Total Page:16
File Type:pdf, Size:1020Kb
Behavior Research Methods, Instruments, & Computers 2000, 32 (2), 290-296 MATLAB and graphical user interfaces: Tools for experimental management ERINM.HARLEY and GEOFFREY R. LOFTUS University ofWashington, Seattle, Washington MATLAB is a convenient platform for the development and management of psychological experi ments because of its easy-to-use programming language, sophisticated graphics features, and statistics and optimization tools. Through implementation of the Brainard-Pelli Psychophysics Toolbox, the MATLAB user gains close temporal and spatial control over the CRT, while retaining the simplicity of an interpreted language conducive to rapid program development. MATLAB's abilities can be further utilized through easily programmable graphical user interfaces (GUIs). We illustrate how a GUI can serve as a powerful and intuitive tool for organizing and controlling all aspects of a psychological ex periment, including design, data collection, data analysis, and theory fitting. We describe here three related topics: first, the use of forms, such as PSYSCOPE (Cohen, MacWhinney, Flatt, MATLAB in psychological research; second, the value of & Provost, 1993; Yee & Vaughan, 1999) and MEL graphical user interfaces (GUIs) in organizing and running (St. James & Schneider, 1991; Schneider, 1989), because experiments; and third, our implementation of one such it provides greater control over experimental design, al GUI within the MATLAB environment. lowing for the creation of entirely unique experiments. MATLAB also serves as a good alternative to low-level MATLABAND programming languages, such as C and PASCAL, be PSYCHOLOGICAL RESEARCH cause MATLAB's language is abstracted from the hard ware details and is generally easier to learn. As a result, Over the past few years, MATLAB (a product of The a MATLAB user receives the benefits ofa programming Math Works Inc.) has gained popularity as a means of language that is both conducive to rapid program devel running psychological experiments, particularly those opment and able to perform with the power and flexibil involving perception and cognition. MATLAB, which ity ofa low-level language (primarily through the addition stands for matrix laboratory, is a powerful platform for ofthe Psychophysics Toolbox, discussed below). high-performance mathematical computation and graph ical representation, whose basic data element is an N The Psychophysics Toolbox dimensional matrix (Hanselman & Littlefield, 1996). MATLAB is particularly useful for running sensory MATLAB's primary strength as a means for creating and and perceptual experiments, largely owing to an exten executing psychological experiments lies in its compre sive set of tools-the Psychophysics Toolbox;' written hensive package ofsuperior mathematical and graphical by Denis Pelli and David Brainard-that allows extremely tools. Within this single application, all ofthe following close temporal, spatial, and color-related control over CRT experimental tasks can be achieved: creation and manip based stimulus displays (Brainard, 1997; Pelli, 1997). ulation ofstimuli, design and execution ofthe experiment, Specifically, the toolbox provides access to the comput data collection, statistical analysis, fit ofcomplex theory er's display frame buffer and color lookup table, allows to data, and interactive graphical data display. synchronization of stimulus display with the vertical re MATLAB runs on Macintosh,' Windows, and UNIX trace, supports millisecond timing, and facilitates the col operating systems and includes both a programming lan lection ofobserver responses (Brainard, 1997). The tool guage and a large set ofmathematically oriented libraries.? box incorporates these features into a large collection of MATLAB serves as a good alternative to popular plat- stimulus-display routines that allow the user to store pre formed visual images (e.g., scenes, forms, text, or some combination ofthese) in the computer's memory and to The writing of this manuscript was supported by NIMH Grant MH4I637 to G.L. We thank David Brainard for enormous amounts of display these images at rates that are constrained only by help in understanding the Psychophysics Toolbox and MATLAB in gen the monitor's refresh rate. For example, on a Macintosh eral. The MATLAB code discussed in this article will be posted on E.H.'s G3 computer, a 400 X 400 pixel gray-scale image can be Web site (http://students.washington.edu/eharley/). Please e-mail either transferred from memory to the screen buffer in less than of the authors for details. Correspondence concerning this article should be addressed to E. M. Harley, Department of Psychology, Uni 10 msec, thereby allowing a sequence ofsuch images (the versity of Washington, Seattle, WA 98195-1525 (e-mail: eharley@ number ofwhich is limited only by computer memory) to u.washington.edu). be displayed at the fastest possible rate. Copyright 2000 Psychonomic Society, Inc. 290 MATLAB AND GRAPHICAL USER INTERFACES 291 The Psychophysics Toolbox has been used by re Like other programming platforms, MATLAB provides searchers to study a variety oftopics in the field ofpsy automatic formatting features, such as color coding of chology, including face and object recognition, psycho comments, strings, and key words, as well as indentation physical thresholds, color matching, visual search, of loops, thus increasing clarity and organization of pro categorization, motion detection, and perceptual learning. gramming code. The net effect ofsuch features, combined Later in this article, we will briefly discuss our use ofthe with MATLAB's simple and intuitive programming syn toolbox to display high- and low-pass filtered digit strings tax, is to allow someone with little or no prior program for very briefexposure durations. ming experience to quickly become a proficient MAT LAB programmer and to write sophisticated routines Tools for Data Analysis and Theory Fitting within a matter of weeks. MATLAB provides a wide range of functions for use in data analysis. For example, the optional Statistics Graphical User Interfaces Toolbox includes more than 200 routines covering topics There are essentially three ways in which a user can including, but not limited to, descriptive statistics, prob communicate with the computer via MATLAB: through ability distributions, linear and nonlinear modeling, multi the Command Window, through the use of scripts and variate statistics, and hypothesis testing. MATLAB also functions, and through GUIs. provides graphing tools for the creation ofpresentation The Command Window is MATLAB's default I/O tech quality plots of various forms, including line, scatter, nique. As the name implies, it is a window into which any stem, pie, and box plots and bar graphs and histograms, as standard MATLAB commands or user-defined com well as three-dimensional contour, surface, and mesh plots mands, such as "2+2" or "answer = conv2 (mask, filter)," (with optional animation). can be typed. Although the Command Window is ade Experimenters in the field ofperception and cognition quate for accomplishing simple tasks, it is often useful to often wish to fit mathematical theory to their data. MAT create a file containing a list of such commands. These LAB's optional Optimization Toolbox provides the tools files are called scripts if they simply run a list of com necessary for fitting complex, nonlinear mathematical mands and functions if they accept input arguments models with a number offree parameters but no analytic and/or return output arguments. Both scripts and func solution. For a given data set, the optimization routines tions can be executed either directly from the Command find the values ofthe free parameters that minimize some Window or from within other scripts or functions. To pro desired error function (e.g., the root-mean square error vide an example, a function that we wrote and use often between the data and the theory predictions). is called "ComputeContrast." It requires two input val ues, foreground color (FC) and background color (BC), MATLAB's Intuitive Programming Language and returns the contrast value calculated by the formula MATLAB incorporates a programming language that (FC - BC)/(FC + BC). is similar in structure to many common languages, such The third communication device, a GUI, provides an as FORTRAN, BASIC, PASCAL, and C. One element intuitive interface between the user and the program that makes MATLAB's language unique is that, as was ming language. A GUI allows the user to bypass MAT noted, it uses a matrix as its basic element. This property LAB commands altogether and, instead, to execute pro confers numerous benefits, one being the following: In gramming routines with a simple mouse click or keypress most programming languages, it becomes time consum (most common applications, such as Word and Photo ing and cumbersome to perform the same mathematical shop, as well as the Macintosh and Windows operating operation on a group of numbers, because the operation systems, are implemented as complex GUIs). No knowl must be repeated (generally via loops) for each number, edge ofMATLAB or computer programming is necessary one number at a time. The greater the dimensionality of for a user to successfully navigate a well-designed GUI; the data structure on which such operations are per indeed, from the user's perspective, the language under formed, the greater the number of embedded loops re lying the GUI is irrelevant. GUIs can range from simple quired.