How to allow an input while an image is displayed

Hi there,
I am wondering how I can get a user to input a text while showing them an image. I am testing reaction time, so I would need the user to be able to input their response immediately after image presentation. So for example, I display an image of a dog, and then the user would have to immediately type in dog and press enter, and then the next image would appear next, and then the user would have to input their response, and so on.
Thank you!

Answers (1)

For any work similar to that, we recommend Psychtoolbox http://psychtoolbox.org/ which is specifically designed for that kind of psychometric experiment. It goes through a lot of trouble to try to ensure accurate timing

2 Comments

Hmm. I'm not familiar with psychtoolbox - is there way to almost hard code what I'm trying to do on the basic MATLAB interface?
No, there is no possibility that you can get accurate enough timing information in basic MATLAB.
See https://www.mathworks.com/matlabcentral/answers/143088-real-time-detect-keypress#answer_285124 for a discussion of the different key treatments in Psychtoolbox
Also, as of R2014b, MATLAB graphics got divided into multiple internal threads, with the program continuing on after it changed graphic information structures, with a different thread taking over interpreting the meaning of the changes to the data structures and figuring out how to convert the data structures into graphics. Because it is now in seperate threads, there is no way in MATLAB to know whether the delay is between the time that you make a graphics change and the time it appears on the screen. It can also be difficult to prevent graphics from showing up before you want them to in some cases.
Sometimes you create some graphics commands and you want them to be processed internally in order to be able to query the effect that they had on the data structures, even though you do not actually want them to show up yet. MATLAB does not update all of the data structures associated with objects whose visibility is off. If you want to know, for example, what axis limits were chosen automatically for a series of graphics commands, so that you can (for example) draw lines from limit to limit, or construct "nice" tick labels, then you need to make the objects visible and make the figure visible, because the data structures are not updated for invisible figures. So you might end up having to make incomplete graphics visible in order to get graphics information back.
Another case where it is a problem is that if you are trying to dynamically size a uicontrol or similar object to be "just big enough" to hold some particular text, then after the object has been rendered, you can ask for the graphic Extent property. But you had to let the object be made visible to do that. And you might have a whole bunch of such objects being dynamically placed to "look nice", and you really don't want the intermediate "trial" objects to become visible to the user... but you have to risk it to get the information you need.
Psychtoolbox makes those kinds of issues explicit: to within the commands offered by the toolbox, you have control over when something gets sent to the screen, including be able to say that you want it made available to the user on the next full-frame screen refresh. The object is either not visible at all, or is completely visible (with modern hardware), so you do not have to worry about possibilities such as that the image might have partly gone out half-way through a refresh... and then how do you time that accurately?

Sign in to comment.

Products

Asked:

on 9 Dec 2020

Edited:

on 10 Dec 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!