Mental Rotation Replication in Matlab

by on Sep.08, 2009, under Cognitive Science, Programming

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.

8 Comments for this entry

  • Julia Mossbridge


    Any way you’d consider sharing your code for this task?



  • Julia Mossbridge

    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.



  • Julia Mossbridge

    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.


  • Ben

    Any chance you could make a set of screendumps (png jpg or other) of the stimuli available?


  • Pedro

    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?


  • Julia Mossbridge

    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?



  • Julia Mossbridge

    Figured it out!

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


Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!


A few highly recommended websites...