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')

Antworten (1)

per isakson
per isakson am 12 Aug. 2013
Bearbeitet: per isakson am 12 Aug. 2013

0 Stimmen

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 Kommentare

Thank you so much for the quick response! I'm still having some trouble with my code it other than datenum that'snot letting it run correctly.
I keep getting the following error when running this
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},'yyyy-mm-dd HH:MM:SS.FFF')
if isempty(best_sentence_selection_t{a}) == 1
bTime = 0
else
bTime = datenum(best_sentence_selection_t{a},'yyyy-mm-dd HH:MM:SS.FFF')
if isempty(worst_sentence_selection_{a}) == 1
wTime = 0
else
wTime = datenum(worst_sentence_selection_{a},'yyyy-mm-dd HH:MM:SS.FFF');
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')
In an assignment A(I) = B, the number of elements in B and I must be the same.
Any ideas?
per isakson
per isakson am 12 Aug. 2013
Bearbeitet: per isakson am 12 Aug. 2013
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
Mary am 12 Aug. 2013
Sorry about that - I resolved the problem - (I wasn't calling an entire vector instead of just one piece)
I'm still having problems with the datestr though. I continually get back an error that it could not process datenum with this format datenum(worst_sentence_selection_{a},'yyyy-mm-dd HH:MM:SS.FFF')
I've tried pulling out just the second/millisecond information, but for some of these the change in on the hour (one selection made at 11:59 and the other at 12:00), so it's not accurately giving me a difference between times.
Thank you again for the help! Please let me know if you have any other ideas!
per isakson
per isakson am 12 Aug. 2013
Bearbeitet: per isakson am 12 Aug. 2013
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
Mary am 12 Aug. 2013
question_display_time best_sentence_selection and worst_sentence_selection
are all in the format 'yyyy-mm-dd HH:MM:SS.FFF'
- three digits of milliseconds would be plenty- it's just that MATLAB isn't taking that format in datenum (it errors everytime)
- If I try to take the date in a smaller format (for example) MM:SS.FFF it works - but I have the 11:59 - 12:00 problem, where it takes every hour as 00:MM:SS.FFF
sorry for the confusion
thank you again
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
Mary am 12 Aug. 2013
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 am 12 Aug. 2013
Bearbeitet: per isakson am 12 Aug. 2013
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Gefragt:

am 12 Aug. 2013

Community Treasure Hunt

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

Start Hunting!

Translated by