JA_Average_previous_trials.m 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. function [Par] = JA_Average_previous_trials(Par)
  2. moving_avg = 5;
  3. fixed_RT = 0.4;
  4. % at the very first trial of the block, SBJ_RT is not known
  5. % so it is set at 0.4 + charge = 0.7
  6. if Par.tr == 1 % if it is the first trial of the very first game
  7. % set it to a standard velocity
  8. Par.CF_RT{Par.tr} = fixed_RT + Par.charge; % 0.4 + charge
  9. Par.SBJ_RT_median{Par.tr} = Par.CF_RT{Par.tr};
  10. %return soon after assigning the fixed_RT to the CF_RT of the current trial
  11. % so the reading does not enter the next if cycles
  12. return
  13. end
  14. % then, it is possible that the SBJ anticipates/posticipates at the second
  15. % trial so there would be no info av avilable about SBJ RTs yet
  16. % if trial is the second one, check if there is already a valid SBJ_RT from
  17. % the trial before
  18. if (Par.tr == 2) && isempty(Par.SBJ_RT{Par.tr-1})
  19. % for now assign a value to SBJ_RT even though no response has been
  20. % provided. In case for example, SBJ does not produce a valid response in
  21. % the preceding (first) trial, keep CF_RT at fixed_RT value
  22. Par.CF_RT{Par.tr} = fixed_RT + Par.charge; % 0.4 + charge
  23. Par.SBJ_RT{1} = Par.CF_RT{Par.tr}; % 0.4 + charge
  24. Par.SBJ_RT_median{Par.tr} = Par.CF_RT{Par.tr};
  25. return
  26. end
  27. % if the script gets here it means that there is at least one number in
  28. % the SBJ_RT up to trial 2. so, until trials are 'movging_avg' number do
  29. % median onto the available values
  30. if (Par.tr >= 2) && (Par.tr <= moving_avg)
  31. % median between trial 1 to eventually trial 4 to put as CF_RT in
  32. % trials up to 5 (moving_avg)
  33. Par.CF_RT{Par.tr} = median(cell2mat(Par.SBJ_RT(1:Par.tr-1)));
  34. Par.SBJ_RT_median{Par.tr} = Par.CF_RT{Par.tr};
  35. return
  36. end
  37. % from trials >= 6
  38. if (Par.tr > moving_avg)
  39. % PAY ATTENTION if too many no-responses it throw errors
  40. % Par.SBJ_RT
  41. %
  42. % ans =
  43. %
  44. % [0.7000] [] [] [] [] [] []
  45. if ~isnan(median(cell2mat(Par.SBJ_RT(Par.tr-(moving_avg):Par.tr-1))))
  46. % slide the median considering only the last 'moving_avg' number of trials
  47. Par.CF_RT{Par.tr} = median(cell2mat(Par.SBJ_RT(Par.tr-(moving_avg):Par.tr-1)));
  48. else
  49. Par.CF_RT{Par.tr} = median(cell2mat(Par.SBJ_RT(1:Par.tr-1)));
  50. end
  51. Par.SBJ_RT_median{Par.tr} = Par.CF_RT{Par.tr};
  52. return
  53. end
  54. %logging{Par.tr}.RT_SBJ_avg = RT_SBJ_avg{Par.tr};
  55. end