How to catch reaction time with MATLAB; How to save text file from command window automatically

조회 수: 20 (최근 30일)
Dear all
I would like to ask two questions:
1. I use command "fprintf" to write the result to command window, and I was wondering: does MATLAB have the command that can save the result posted on command window " automatically" ?
2. I have written a script to catch the reaction time( the time between picture appears and the participant's response by pressing the keyboard( it work with cogent). I use "tic" and "toc" to set the time start and stop to get this period. But I don't know why I put "toc" in the " if" statement, it cannot read.
ex.
S1=tic;
[ks, kp] = cgkeymap;
kp=find(kp);
if kp==77 %key:righ
S2=toc(S1);
kp=77 means to press the right key, and Matlab should detect this and record S2....But I am confused why it cannot work.
I hope any expert can help me and I will be grateful for your kind help.
Many thanks in advance
  댓글 수: 3
Hopester Hope
Hopester Hope 2012년 3월 8일
Surely that's only true if the sources of latency are correlated with your effect(s) of interest? If not, those sources of latency are essentially noise, which will diminish the power of your experiment, but still leave it perfectly valid.
Daniel Shub
Daniel Shub 2012년 3월 8일
@Hopester you are correct that the main effect will be to diminish the power. The problem is that for many experiments it will diminish the power to such an extent that the data will be meaningless (especially if the power calculation does not take into account this additional noise). The other effect is that I don't tend to trust results in which the experimenter choses not to take simple steps to eliminate a huge source of noise.

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

답변 (3개)

Ian
Ian 2011년 9월 6일
Um, cogent is really not very good for precise timing, and in addition you are not controlling for any OS/hardware latency fluctuations. My advice, if you actually care about recording reaction times accurately, is to first use Psychophysics toolbox, which timestamps the flip with high precision and corrects for OS latency (that is the time you use for S1, much more accurate than a tic after cgflip), and also returns a time with its keypress functions which is used to determine the reaction time:
Secondly, you should really use a hardware button box - keyboards and mice have a poll latency in the 10s of milliseconds (at least in Windows) which is fairly inaccurate (at least in psychophysics). Button boxes overcome the inaccuracy by using an internal high resolution hardware timer and a way to synchronise with the host computer.

Chaowei Chen
Chaowei Chen 2011년 9월 3일
1. doc diary 2. I think the problem happens at kp=find(kp) It means wherever kp is nonzero, assign the position to kp.
My modification is
S1=tic; [ks, kp] = cgkeymap; if kp=='M', S2=toc(S1),end

Kristina
Kristina 2011년 9월 5일
Hi thanks for the answer. For 1,the command 'diary' works well. For 2,
cgellipse(-150,0,15,15,[1 1 1],'f');
cgflip(0,0,0); S1=tic;
[ks, kp] = cgkeymap;
kp=find(kp);
if (~isempty(kp)) && (kp == 77) %key:righ
S2=toc(S1);
S1 appears after the last graph(dot) to record the start time. But the reaction time is always close to zero(e.g.0.00063s),means no change for this time. Hope anyone can find out the problem,thanks
  댓글 수: 1
Fangjun Jiang
Fangjun Jiang 2011년 9월 5일
0.00063s is not really that close to zero. It seems reasonable to me! Try a few other examples or take a look at 'doc tic'.

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

카테고리

Help CenterFile Exchange에서 Timing and presenting 2D and 3D stimuli에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by