Mental Rotation Replication in Matlab

I recently replicated a Shepard and Metzler (1971) style experiment in order to explore OpenGL programming under Matlab. Additionally, I wanted to manipulate certain variables, such as the
type(class) of object, to verify predictions made by emerging models of
top-down processes of human vision such as those mentioned in the previous post. This replication provided a convenient point to start.

In this implementation, the participant is shown a series of 3D object pairs. On some trials, the two objects are different. On other trials, one object is simply a rotation on the xy plane of the other object by a variable multiple of 20 degrees. The participant responds by pressing ‘1’ to indicate the same object or ‘2’ to indicate different objects while their response time is measured. Previous research shows that response time increases linearly relative to the number of degrees one object is rotated from the other (Shepard, Metzler 1971).

The image to the right below shows the stimuli for one trial. The image to the left depicts my own results for 100 trials. My response time is far less than the typical Shepard (1971) subject but I have years of experience working with 3D graphics and, of course, wrote the code for this experiment. I’ve posted the code as I think it provides a decent example of accessing OpenGL from Matlab and a good starting point for related experiments. The code is available for download here.

Shepard R., Metzler J. (1971). Mental Rotation of Three-Dimensional Objects. Science. 171.3972, 701-703.

10 thoughts on “Mental Rotation Replication in Matlab

    1. There’s a link to the code in the last sentence of the post (the word ‘here’). Not the most noticeable thing 😉

  1. Hi Trystan —

    I downloaded and ran the code. It works very well, while I’m running it. However, it’s not clear how to get the data. When it’s done, the command window just displays:
    Callback: @DataBlack/Callback
    Plot: @DataBlock/Plot
    Data: @DataBlock/Data

    I’m wondering where I can see the data.



  2. Oh, never mind! I see the data were appearing on a figure that wasn’t pushed forward. Sorry!

    Thanks for the script. It’s great.


  3. Dear Trystan,

    Thanks a lot for your matlab code; it runs perfectly! Unfortunately, I’m not very familiar with OpenGL and I’m having a hard time understanding how you actually generate those snake stimuli. I know this is an already old project of yours but is there any chance that you comment your code?


  4. Hi Trystan,

    I’m going through and getting PNG files for each of the different images, and I discovered that sometimes even if I set the code for diff=true, some of the images are the same anyway.

    Do you know how to fix this?



  5. Figured it out!

    Added code that checked the objOrder to make sure that when diff=1, they are not the same.


  6. Hello,

    I am a cognitive science student at UCLA. We’re using the mental rotation code for a psychophysics project.

    Think we can chat on the phone or Skype? It would be great to ask you some questions we have.



  7. Hello!

    I am trying to use this code by every time I try and run the code it says Trials is an undefined function or variable. I’ve added it to the matlab path and have psychtoolbox downloaded… I’m sure I’m making a stupid mistake somewhere along the line!

Leave a Reply

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