On the one hand, Matlab is just a mathematical programming language that can be mainly used to manipulate (preferable huge) matrices and vectors. Yet, on the other hand, it can be extended by adding so-called toolboxes. The big plus of Matlab is that there exists an enormous collection of various toolboxes, from an auditory perception toolbox to aircraft control simulation include 3-D graphics.
The toolboxes are either written in the Matlab language itself or can be programmed in C and FORTRAN. Thus (and if you can program in C/FORTRAN) it is relatively straightforward to provide a Matlab function for whatever you are normally do with your computer.
The PsychToolbox is such a collection of functions that are often useful for psychological experiments. The core piece are some functions to precisely register key presses, to display images rapidly and in synchrony with the monitor refresh signal, to calibrate the monitor, and a good deal more. In this tutorial we will just concentrate on the keyboard and display functions which will be sufficient for the majority of (non-vision) experiments.
Experiments commonly consists of single trials. Each trial belongs to one condition and in the extreme case there can be as many conditions as trials. But usually a condition is repeatedly presented in several trials. Since Matlab is a mathematical language it is not at all surprising that this information is stored in vectors or matrices.
> c = [ 1 2 3 ];
c =
1 2 3
> d = repmat(c, 5, 1)
d =
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
> e = d(:)'
1 1 1 1 1 2 2 2 2 2 3 3 3 3 3
However, it is much more interesting than printing the condition vector is to visualize it with one of the many plotting commands of Matlab. The easiest is the basic plot command. The second parameter 'o' instructs Matlab just to draw the tiny circles (and no lines).
> plot(e, 'o')
> c = randperm(3)
c =
3 1 2
> d = repmat(c, 5, 1); e = d(:)'; plot(e, 'o');
> c = [ 1 2 3 ]; d = repmat(c, 1, 5)
d =
1 2 3 1 2 3 1 2 3 1 2 3 1 2 3
> plot(d, 'o')
> r = randperm(15)
r =
Columns 1 through 13
10 13 12 3 8 2 5 4 1 15 6 14 9
Columns 14 through 15
7 11
To reorder the conditions in E one can use the permutation vector R. R(1) is 10, thus, if we take the 10th entry D(10) we will have 1. The second entry in R is 13 and E(13) is 1 again. From R(3) = 12, we will get E(12) = 3. Thus, the resulting vector will start with 1 1 3 ....
> f = e(r)
f =
Columns 1 through 13
1 1 3 3 2 2 2 1 1 3 3 2 3
Columns 14 through 15
1 2
> plot(f, 'o')
Page Execution took 2.754 seconds |