Moving dot at a constant velocity on Matlab

4 views (last 30 days)
Hi. I am trying to design an experiment using Matlab with Psychophysics toolbox. I want to present a white dot in a black background and make it move at a constant velocity towards the participant (the dot will have to inscrease in size when approaching). Additionally I want to manipulate the initial position in which it will be presented. Can anyone help me ? I already draw a white dot in the center of the screen with the function Screen('BlendFunction' ... ) but I seem to be unlable to make it move.
Thank you, Mariana

Accepted Answer

Rosa Mariana Silva
Rosa Mariana Silva on 10 Feb 2015
Thank you for your help!
So far I was able to do this:
[screenXpixels, screenYpixels] = Screen('WindowSize', window); [xCenter, yCenter] = RectCenter(windowRect); InitializePsychSound; Screen('Flip', window); 0; dotColor = [1 1 1]; HideCursor;
start_time = GetSecs; i=1; elapsed_time = 0;
PsychPortAudio('Start', pahandle, 1, 0, []); while elapsed_time < 0.5
raio = (i*10);
r = [xCenter-raio, yCenter-raio, xCenter+raio, yCenter+raio];
elapsed_time = GetSecs - start_time;
tam = i * 10;
t=t+1;
i=i+1;
s(t)= Screen(window, 'Flip');
end
Screen('Flip', window); KbStrokeWait; sca
It works fine! But now, I need to generate the dot at a certain position (in depth) and approaching the observer at a certain constant speed. So what I want to do is to determine the size of the dot at the beginning of presentation and then increase its size until the end of the presentation. do you know how can I do that in this bit of code that is above?
Many thanks for your help! :)

More Answers (1)

Vaibhav Gupta
Vaibhav Gupta on 8 Jan 2015
Edited: Vaibhav Gupta on 8 Jan 2015
If you know the initial position of the dot and you know the velocity, you can calculate the position of the dot at any given time. Suppose you start at time t=0 at position x=0 and you have a velocity of v=2units/time along the positive x direction, the position of the dot at any given time t will be x=0+2*t. So, just increment the time and keep plotting the dot.
A simple code would be:
% code
x0 = 0;
y = 0;
v = 2; %Velocity of 2
for time=1:100
x = x0 + v*time;
plot(x, y,'r*'); %Plot the red dot
axis([-1 250 -10 10])
drawnow();
%pause(0.1)
end
  3 Comments
Youssef  Khmou
Youssef Khmou on 8 Jan 2015
Rosa, you can try this code as continuation of the above version :
x0 = 0;y = 0;v = 2 %Velocity of 2
r=linspace(0.2,10,100);
c=1;
for time=1:100
x = x0 + v*time;
plot(x, y,'o','MarkerSize',r(c)); %Plot the red dot
c=c+1;
axis([-1 250 -10 10])
drawnow();
%pause(0.1)
end

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!