Finding Reaction Time from DateStrings
1 回表示 (過去 30 日間)
古いコメントを表示
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')
0 件のコメント
回答 (1 件)
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 件のコメント
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 Center および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!