Finding Reaction Time from DateStrings

2 次查看(过去 30 天)
Mary
Mary 2013-8-12
I'm trying to obtain a reaction time for datestrings obtained during a behavioral experiment
the date string formats from the experiment log files look like this: 'year-month-day hour:minute:second.ms'
example: '2013-08-01 00:30:10:12345'
I have three different datestr's I would like to look at and work with (question, best and worst)
If someone did not respond to a question during the experiment the cell was left blank (reason for isempty check)
Below is a code I am trying to run after loading the log file and variables, but I can't seem to get it to work
Thank you in advance for any help or advice!!! :)
a=2 b=1 for i = 1:numel(version_id)
if isempty(question_display_time{a}) == 1
qDisp = 0
else
qDisp = datenum(question_display_time{a})
if isempty(best_sentence_selection_t{a}) == 1
bTime = 0
else
bTime = datenum(best_sentence_selection_t{a})
if isempty(worst_sentence_selection_{a}) == 1
wTime = 0
else
wTime = datenum(worst_sentence_selection_{a});
end
end
end
bRT(b) = bTime - qDisp
wRT(b) = wTime - qDisp
if bRT(b) >= wRT(b);
respondedFirst{b} = {'Worst'};
betweenTime(b) = bRT - wRT;
else
respondedFirst{b} = {'Best'};
betweenTime(b) = wRT - bRT;
end
a=a+1;
b=b+1;
end
xlswrite('RT.xls' ,bRT,'A1') xlswrite('RT.xls',wRT,'B1') xlswrite('RT.xls',respondedFirst,'C1') xlswrite('RT.xls',betweenTime,'D1')

回答(1 个)

per isakson
per isakson 2013-8-12
编辑:per isakson 2013-8-12
Try
str = '2013-08-01 00:30:10:12345';
num = datenum( str, 'yyyy-mm-dd HH:MM:SS:FFF' );
Doc says:
FFF, Millisecond in three digits
if that isn't good enough one has to handle "12345" separately. Try
cac = regexp( str, ':', 'split' );
str2num(cac{end})/1e5
and
dif = datenum(str,'yyyy-mm-dd HH:MM:SS:FFF') - datenum(str,'yyyy-mm-dd HH:MM:SS')
  8 个评论
Mary
Mary 2013-8-12
I have formatting similar to above - except for ms, it's MM:SS.FFF instead of MM:SS:FFF. Do you think that could be making a difference (i've tried both colon and period formats)?
Thanks
per isakson
per isakson 2013-8-12
编辑:per isakson 2013-8-12
The format-string and the date-string must match! Either, ":" in both or "." in both.
This returns an error
str = '2013-08-01 00:30:10:12345';
num = datenum( str, 'yyyy-mm-dd HH:MM:SS.FFF' );
returns
Error using datenum (line 179)
DATENUM failed.
Caused by:
Error using dtstr2dtnummx
Failed on converting date string to date number.
Your question contains, "'year-month-day hour:minute:second.ms' [...] example: '2013-08-01 00:30:10:12345'", which is in error. There is a "." between "second" and "ms", but in the corresponding position in the date-string there is a ":". I missed that.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Historical Contests 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by