Outpt with zeros when should be values
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Krispy Scripts
el 1 de Dic. de 2016
Comentada: Krispy Scripts
el 6 de Dic. de 2016
I have a matrix of two columns. The first column is cue times, as in times an animal was cued to do something. The second column is times that the animal responded. If the animal correctly responded then the animal will respond within a range greater than .15 seconds of cue and less then 5 seconds from cue. If so this is a correct behavior and needs to go into one matrix(correcttrials), if not then this is an error behavior and needs to go in a second matrix(errortrials).
The original Matrix (I have also attached it):
intervals =
81.4358 735.1798
272.0970 1442.0839
515.2985 1682.2252
575.41885 1961.58675
734.95985 2507.14965
915.20085 2681.83055
1319.4032 2682.0705
1441.0439 2777.6710
1526.62435 3498.9947
1681.4852 0
1961.38675 0
2087.0074 0
2372.6089 0
2559.9099 0
2681.73055 0
2838.63135 0
3049.3324 0
3140.97285 0
3322.3738 0
3498.87465 0
This is the code I have written, but I am not sure why the correct output has zeros in it and the error output gets all zeros.
Here is my code:
data=intervals;
cue=data(:,1);
response=data(:,2);
for k=1:length(cue)
for i=1:length(response)
if reward(i)>= (cue(k)+.15) && reward(i)<= (cue(k)+5)
correcttrials(i)=response(i);
else
errortrials(i)=response(i);
end
end
end
Here are the Matrices I am getting out:
Correct Trials:
correcttrials=
735.1798 1442.0839 1682.2252 1961.58675 735.1798 0 2682.0705 1442.0839 0 1682.2252 1961.58675 0 0 0 2682.0705
Error Trials:
errortrials =
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
I am intending to get:
Correct Trials:
correcttrials =
735.1798 1442.0839 1682.2252 1961.58675 2682.0705
Error Trials:
errortrials =
2507.14965 2681.83055 2777.6710 3498.9947
1 comentario
Image Analyst
el 1 de Dic. de 2016
We can't run this code because you have not defined the reward array.
Respuesta aceptada
Andrei Bobrov
el 2 de Dic. de 2016
intervals = [...
81.4358 735.1798
272.0970 1442.0839
515.2985 1682.2252
575.41885 1961.58675
734.95985 2507.14965
915.20085 2681.83055
1319.4032 2682.0705
1441.0439 2777.6710
1526.62435 3498.9947
1681.4852 0
1961.38675 0
2087.0074 0
2372.6089 0
2559.9099 0
2681.73055 0
2838.63135 0
3049.3324 0
3140.97285 0
3322.3738 0
3498.87465 0];
d = intervals;
dn0 = d(d(:,2)~=0,2)';
da = abs(d(:,1) - dn0);
t = any(da > .15 & da < 15);
correcttrials = dn0(t)
errortrials = dn0(~t)
2 comentarios
Más respuestas (1)
Image Analyst
el 1 de Dic. de 2016
Try this vectorized way:
load('intervals.mat');
cueTimes = intervals(:,1); % Extract the first column.
responseTimes = intervals(:,2); % Extract the second column.
% Get the time differences.
timeDifferences = responseTimes - cueTimes
% Convert from milliseconds to seconds. ??????????
timeDifferences = timeDifferences / 1000;
correctTrialsRows = (timeDifferences > 0.15) & (timeDifferences < 5)
correctTrials = responseTimes(correctTrialsRows)
errorTrials = responseTimes(~correctTrialsRows)
None of the things was correct so I figured the times might be in milliseconds whereas your criteria was in seconds, so I converted. I'm still not sure if this gives you what you want though.
2 comentarios
Image Analyst
el 2 de Dic. de 2016
Editada: Image Analyst
el 2 de Dic. de 2016
Then none of your time differences are in the range 0.15 to 5 seconds. Let's take a typical start/stop pair - the pair in row #5. Start/cue time of 734.95985 seconds, and response (stop time) at 2507.14965 seconds. That's 1771 seconds. And all the rest are like that. Not one of them is in the range 0.15 to 5 - they're all hundreds.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!