How do I set a certain duration for a stimuli presentation?

조회 수: 5 (최근 30일)
Kathryn Fransen
Kathryn Fransen 2015년 3월 4일
댓글: Jos (10584) 2015년 3월 7일
I have a small white spot presented on a grey background. I would like to have the spot stimuli on for 2 secs and then switch to only the grey background for 5 secs. I need help in setting the duration for each stimuli presentation. Also, I need the timing to be as accurate as possible.
  댓글 수: 1
Chris McComb
Chris McComb 2015년 3월 4일
편집: Chris McComb 2015년 3월 4일
Are you after something like this?
% Number of stimuli
n = 5;
for i=1:1:n
% Plot the spot
h = plot(x_spot, y_spot);
% Pause for 2 seconds
pause(2);
% Delete the spot
delete(h);
% Wait for 5 seconds
pause(5);
end

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

답변 (1개)

Jos (10584)
Jos (10584) 2015년 3월 4일
I suggest you do not use delete and pause. Here is an alternative
x = [1 2 6 8 3] ;
y = [7 1 3 9 6] ;
stimtime = 1 ; % time to show a spot
waittime = 2 ; % time to wait between spots
% create a plot
clf ; % clear current figure
h = plot(NaN,NaN,'bo','markerfacecolor','r') ;
set(gca,'xlim',[0 10],'ylim',[0 10]) ;
for k=1:numel(x),
set(h,'xdata',x(k),'ydata',y(k),'visible','on') ;
drawnow ;
tic ;
while toc < stimtime, end
set(h,'visible','off') ;
drawnow ;
while toc < stimtime+waittime, end
end
  댓글 수: 2
Kathryn Fransen
Kathryn Fransen 2015년 3월 6일
Thank you for your answer. I see how tic and toc work for the example you presented, however, I am having a hard time getting it to work with my stimuli code. I have attached the stimuli code (I use the psychophysics toolbox, so I am not sure if this function will work without the toolbox?). I need to add a timing element to this code allowing for the spot image to be presented for 2 seconds, and then I will add in code for a blank grey background for 5 seconds. I then would like to make this loop 5 times. Do you have any suggestions on how I can use tic and toc with the stimuli I am working with? I have tried many things, but can't get anything to work.
Jos (10584)
Jos (10584) 2015년 3월 7일
I suggest you take a look at the help of the toolbox, and perhaps ask your question over there. This seems to be a very basic problem more related to psychophysics than to matlab itself.

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

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by