Finding Reaction Time from DateStrings
이전 댓글 표시
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
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
2013년 8월 12일
per isakson
2013년 8월 12일
편집: per isakson
2013년 8월 12일
I "cannot" run and debug your code. You should learn how to use the debugging features.
I would convert the script to a function, which I find easier to debug. Then, I would set
>> dbstop if error
and run the function.
Here are some links on debugging in Matlab
Mary
2013년 8월 12일
per isakson
2013년 8월 12일
편집: per isakson
2013년 8월 12일
My imagination fails me and I don't like guessing
- "worst_sentence_selection{a}" - please provide a couple of examples
- do you need the full precision? Is milliseconds - three digits enough?
- "one selection made at 11:59 and the other at 12:00" Don't you get one minute? What do you get? Examples please!
Mary
2013년 8월 12일
per isakson
2013년 8월 12일
Which release of Matlab do you use? Examples like this
str = '2013-08-01 00:30:10:12345';
num = datenum( str, 'yyyy-mm-dd HH:MM:SS:FFF' );
works fine with R2013a (and several releases back, I'm positive).
However,
str = '2013-08-01 00:30:10';
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.
The date-string must match the full date-format. In this case there is nothing to match ":FFF"
"the 11:59 - 12:00 problem," What do you mean? Please, provide full examples like I do here.
Mary
2013년 8월 12일
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.
카테고리
도움말 센터 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!