drawnow and refreshing screen

I'm using MATLAB 2014b and Windows 7. I have activated vertical sync on my computer. I have defined the following image:
% Create vector white image
img = 255 * ones(600, 600, 3, 'uint8');
% Get handle of the image
handle = imshow(img);
When I run the following code:
tic;
drawnow;
toc;
I expect toc to be aprox. 16 ms since my screen is configured at 60 Hz, so, when I call drawnow, it waits until the next frame to display the image. However, toc is below 10 ms. I can't understand why is this happening.

답변 (2개)

Jan
Jan 2017년 10월 26일
편집: Jan 2017년 10월 26일

1 개 추천

drawnow processes all events waiting to update the interval values of the figure, e.g. rendering of created uicontrol 's or created or changed data of 2D and 3D graphics.
It is not documented, if it triggers an output to the graphic card, and I assume, this does not happen. There is not relation between the time needed by drawnow and the frequency of the monitor, because it updates the contents of the figure, but the syncing with the monitor happens (most likely) as soon as possible afterwards.

댓글 수: 2

Lask
Lask 2017년 10월 26일
and what about "drawnow expose", does it trigger an output to the graphic card?
Jan
Jan 2017년 10월 27일
@E. Valero: Please take a look into the documentation by your own: https://www.mathworks.com/help/matlab/ref/drawnow.html . There you find:
*drawnow expose* updates figures, but defers callbacks. This syntax
is not recommended. Use the nocallbacks option instead.
There is no hint, that it has anything to do with a screen syncing, but this command is even deprecated.
Again: drawnow cares for the update of the properties of figures and all their children, but does not trigger a syncing with the monitor. There is no other command for syncing also in Matlab.

댓글을 달려면 로그인하십시오.

Image Analyst
Image Analyst 2017년 10월 25일

0 개 추천

It probably just sends a message to the video adapter to refresh the screen and then returns to MATLAB without actually waiting for the video adapter to finishing doing that. This is essentially how message based systems work.

댓글 수: 2

Lask
Lask 2017년 10월 26일
So it's impossible to detect the exact same moment the screen refreshes from MATLAB?
Jan
Jan 2017년 10월 27일
@E. Valero: No. I guess you can do this in the Mex level, but this will still have a certain delay due to leaving the Mex function and re-entering the Matlab level. Then "the exact same moment" is not even meaningful.
Please re-think your problem. What do your want to solve actually?

댓글을 달려면 로그인하십시오.

질문:

2017년 10월 23일

댓글:

Jan
2017년 10월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by